Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function saveUser(next) {
- const user = this
- if (user && user.password) {
- user.password = await encodeBcryptPassword(user.password)
- next()
- }
- return null
- }
- userSchema.pre('save', saveUser)
- const User = mongoose.model('users', userSchema)
Add Comment
Please, Sign In to add comment