Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserSchema.pre('save', function(next) {
- const user = this;
- if (this.isModified('password') || this.isNew) {
- return bcrypt.hash(user.password, 10)
- .then((hash) => {
- user.password = hash;
- return next();
- })
- .catch(err => next(err));
- }
- return next();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement