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