Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userSchema.pre('save', function(next) {
- const user = this;
- // only rehash the password if the user alters the password!!!!!
- if (user.isModified('password')) {
- bcrypt.genSalt(10, function(err, salt) {
- if (err) { return next(err); }
- bcrypt.hash(user.password, salt, null, function(err, hash) {
- if (err) { return next(err); }
- user.password = hash;
- next();
- });
- });
- } else {
- next();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement