The function works, for scalability and production concerns I would like to turn this exact function into an async function.
userSchema.methods = {
checkPassword: function (inputPassword) {
return bcrypt.compareSync( inputPassword, this.password )
},
hashPassword: plainTextPassword => {
return bcrypt.hashSync( plainTextPassword, 10 )
}
}
userSchema.pre('save', function (next) {
if (!this.password) {
console.log('models/user.js =======NO PASSWORD PROVIDED=======')
next()
} else {
console.log('models/user.js hashPassword in pre save');
this.password = this.hashPassword(this.password)
next()
}
})