Mongoose Encrypt Password

import bcrypt from 'bcryptjs'

userSchema.pre('save', async function (next) {
  if (!this.isModified('password')) { // if the password is not changed we don't want to hash it again
    return next()
  }

  const salt = await bcrypt.genSalt(10) // creates salt
  this.password = await bcrypt.hash(this.password, salt) //generates hash and combines it with the salt
})
Blue Booby