What I am trying to do:
This HTTP call updates the password in the database. I send the new password to go get hashed and salted in getHashedPassword()
, and this works, at least according to the console.log
where a hash number is printed.
Problem: body data-field does not get updated when I reassign it with the result from the promise, proven by the console log right outside the promise. So thus in the database the new literal string password gets updated but not hash. I'll provide output and pictures in case my explaining is confusing.
router.put('/:id', (req, res) => {
getHashedPassword(req.body.password01).then( result => {
console.log('this is the hashed', result);
req.body.password01 = result;
})
console.log('new passwords', req.body.password01);
BasicUser.findByIdAndUpdate(req.params.id, req.body)
.then(user => res.json({ msg: 'Updated successfully' }))
.catch(err =>
res.status(400).json({ error: 'Unable to update the Database' })
);
});
Console.logs:
new passwords helloagain339
this is the hashed $2b$10$fPw/bHW69mnyltWh0Qn3T.hKIsxbhgTt8/OGxOQXVVRDpTICqZCy.