Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bcrypt from 'bcryptjs'
- userSchema.pre('save', function(next) {
- const user = this;
- if (user.isModified('password')) {
- bcrypt.genSalt(10, (err, salt) => {
- bcrypt.hash(user.password, salt, (err, hash) => {
- user.password = hash;
- next();
- });
- });
- } else {
- next();
- }
- });
Add Comment
Please, Sign In to add comment