我正在使用react js,使用额外的cryptojs作为加密,我尝试在请求数据有效载荷时加密。
我已经做了一个方法,如添加passReqToCallback到我的护照,但它仍然没有得到结果,在控制台请求
我已经将结果作为对象{data:result}添加到加密中,但它仍然不可读,因为有效负载请求读取为数据表单
但结果总是400个错误的请求。最好的方法是什么?
reactjs代码
const handleSubmit = e => {
e.preventDefault();
form.validateFields((err, values) => {
if (!err) {
const postData = {data: encrypt(values)}
setSubmit(true);
// eslint-disable-next-line no-undef
axios.post(`${API}/signin`, postData)
.then(response => {
return console.log('response', response.data);
const data = decrypt(response.data);
setSubmit(false)
if ( _.isString(data) ) {
contentNotification({
type : 'error',
title : 'Error',
placement: 'topLeft',
content : data
})
} else {
contentNotification({
type : 'success',
title : 'Success',
placement: 'topLeft',
content : formatMessage({id: 'LOGIN.SUCCESS'})
});
cookies.set('ckmsbp', response.data);
router.push('/');
}
})
.catch(err => {
contentNotification({
type : 'error',
title : 'Error',
placement: 'topLeft',
content : formatMessage({id: 'LOGIN.ERROR_VALIDATE'})
})
setSubmit(false)
console.error(err);
});
}
});
};
字符串
以下是我的路线:
app.post(`${api_path}/signin`,
validateBody(schemas.loginAccSchema),
requireSignIn,
(req, res, next) => {
const { user } = req
const { decrypt } = req.query
params = { user, decrypt };
const c_account = new ControllerAccount(params);
c_account._postSignin(doc => res.status(200).json(doc))
});
型
最后我的护照
passport.use(new LocalStrategy({
usernameField : 'email',
passReqToCallback : true
}, async (req, email, password, done) => {
// return console.log('req', req);
but do nothing here.. i can't console my request
try{
...
}
catch{...}
型
thanks in advance
3条答案
按热度按时间iqjalb3h1#
在我找到我自己并最终找到我想要的之后
对有效载荷上的数据进行加密的最佳方式是将其加密到对象中,然后当控制器上接收到数据时,再次对其进行解密
然后最重要的方式,当本地策略在护照只想要电子邮件和密码只..所以操纵再次在请求.身体
在React JS中
字符串
在控制器nodejs中,
型
requireSignin函数
型
finaaaalyyy xD
xv8emn3q2#
您可以使用JWT加密并创建后端可以在express处理请求时理解/解码的算法。
字符串
在你的请求有效载荷上,它看起来像这样。
型
ukdjmx9f3#
你能做的就是
字符串
范例:
型