I am working with react js, with additional cryptojs as the encryption, I try to encrypt when requesting data payload ..
I have done a method such as adding passReqToCallback to my passport but it still does not get results in the console request
I have added the results to encryption as object {data: result} but it remains unreadable as a payload request instead reads as a data form
but the results are always 400 bad requests. how is the best way to do it?
my reactjs code
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);
});
}
});
};
here's my routes :
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))
});
and last my passport
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