I'm currently trying to make authentication module for my project in node.js?
I've already seen some examples of using bcrypt to generate hashes, i.e.
https://github.com/bnoguchi/mongoose-auth/blob/master/lib/modules/password/plugin.js https://github.com/Turbo87/locomotive-passport-boilerplate/blob/master/app/models/account.js
However, for some reason they are using bcrypt.hashSync() function. Since bcrypt is good because it's time-consuming, wouldn't it be wiser to use asynchronous function instead in order to not block the code, i.e:
User.virtual('password')
.get( function () {
return this.hash;
})
.set( function (password) {
bcrypt.hash('password', 10, function(err, hash) {
this.hash = hash;
});
});
Could you please explain me which way is better and why? Thank you!