i have registration/login system and for hashing i used third party library bcryptjs and it works (i mean it hashes passwofrd) but problem is that this password is saved raw in database. here is my code of mongoose pre save hook
AdminSchema.pre('save', async function(next){
var user = this;
if(!user.isModified('password')) return next();
bcrypt.genSalt(SALT_WORK_FACTORY, function(err, salt){
if(err) return next(err);
bcrypt.hash(user.password, salt,function(err,hash){
if(err) return next(err);
console.log(hash)
user.password = hash;
console.log(user.password)
next();
})
})
})
and here is save method in registration.js
let admin;
admin = new Admin();
admin.username = username;
admin.password = password;
admin.save(function(err, user){
if(err){
console.log(err)
return res.status(500).send({message:err.message})
}
console.log(user)
const redirectTo = '/';
return res.status(200).send({redirectTo})
})
}
when i log user.password in pre hook it shows me hash
but when i log user in save
it shows me raw text.
what is problem?
Thank you