Guest User

Untitled

a guest
Dec 31st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. userSchema.pre('save', async function (next) {
  2. try {
  3. const user = this;
  4. if (user.isModified('password')) {
  5. const salt = await bcrypt.genSalt(SALT_ROUNDS);
  6. user.password = await bcrypt.hash(user.password, salt);
  7.  
  8. next();
  9. } else {
  10. next();
  11. }
  12. } catch (error) {
  13. next(error);
  14. }
  15. });
Add Comment
Please, Sign In to add comment