Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userSchema.pre('save', function userPreSave(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();
- });
- userSchema.methods.comparePassword = function userComparePassword(password) {
- return bcrypt.compare(password, this.password);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement