Advertisement
Guest User

Untitled

a guest
Oct 30th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. UserSchema.pre('save', function(next) {
  2. const user = this;
  3. if (this.isModified('password') || this.isNew) {
  4. return bcrypt.hash(user.password, 10)
  5. .then((hash) => {
  6. user.password = hash;
  7. return next();
  8. })
  9. .catch(err => next(err));
  10. }
  11. return next();
  12. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement