userSchema.pre('save', function (next) {
const user = this
bcrypt.genSalt(10, function (err, salt) {
if (err) { return next (err) }
bcrypt.hash(user.password, salt, function (err, hash) {
if (err) { return next (err) }
// ovewrite plain text password with hash
user.password = hash
next ()
})
})
})