Guest User

Untitled

a guest
Apr 3rd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. import bcrypt from 'bcryptjs'
  2.  
  3. userSchema.pre('save', function(next) {
  4. const user = this;
  5. if (user.isModified('password')) {
  6. bcrypt.genSalt(10, (err, salt) => {
  7. bcrypt.hash(user.password, salt, (err, hash) => {
  8. user.password = hash;
  9. next();
  10. });
  11. });
  12. } else {
  13. next();
  14. }
  15. });
Add Comment
Please, Sign In to add comment