Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. User.pre('save', function (next) {
  2. const user = this;
  3. if (this.isModified('password') || this.isNew) {
  4. bcrypt.genSalt(10, function (err, salt) {
  5. if (err) {
  6. return next(err);
  7. }
  8. bcrypt.hash(user.password, salt, function (err, hash) {
  9. if (err) {
  10. return next(err);
  11. }
  12. user.password = hash;
  13. next();
  14. });
  15. });
  16. } else {
  17. return next();
  18. }
  19. });
  20.  
  21. User.pre('save', (next) => {
  22. const user = this;
  23. if (this.isModified('password') || this.isNew) {
  24. bcrypt.genSalt(10, (err, salt) => {
  25. if (err) {
  26. return next(err);
  27. }
  28. bcrypt.hash(user.password, salt, (err, hash) => {
  29. if (err) {
  30. return next(err);
  31. }
  32. user.password = hash;
  33. next();
  34. });
  35. });
  36. } else {
  37. return next();
  38. }
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement