New to NodeJS, trying to write user registration by my own, but facing a trouble when app saves non-hashed password. Tried to check if password is hashed before saving and alert says it is. Here's my code:
var userData = {
email: req.body.email,
password: req.body.password
}
var user = userData;
bcrypt.hash(user.password, 10, function(err, hash){
if(err) console.log(err);
user.password = hash;
alert(user.password); //shows hashed password
});
//skipped connection code
database.connection.query("insert into users set ?", user, function(err){ //saves non-hashed password
if(err) console.log(err);
console.log("successfull");
});