This might be opinion based. But I'd like to get some advice.
So, what I want to do can be done in the way mentioned in this thread. But this thread made a good point why I would want to use async.
Here's what I have so far, and it works.
User.create({email: req.body.email, password: req.body.password}).catch(function(err){
console.log(err);
});
User.beforeCreate(function(user) {
const password = user.password;
user.password = '';
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
if(err) console.error(err);
bcrypt.hash(user.password, salt, null, function(err, hash) {
if(err) console.error(err);
user.password = hash;
user.save();
});
});
});
Since I am using bcrypt async, I would have to persist the encrypted password in another query. My gut feeling tells me there might be a better way using bcrypt async with sequelize.
My question is, what is the preferred / better approach? Or should I just settle with using bcrypt synchronously?