'Sequelize -Encrypted Password Update using bcrypt

I have a password update issue with Sequelize. The problem is when I try to update. The password that was previously encrypted by bcyrpt loses encryption. Below is the code where I try to do

hooks: {
  beforeCreate: async user=> {
    const salt = await bcrypt.genSaltSync()
    user.password = bcrypt.hashSync(user.password, salt)
  },
  beforeUpdate:async user=>{
    if(user.password){
      const salt = await bcrypt.genSaltSync()
      user.password=bcrypt.hashSync(user.password, salt)
    }
  }

The encryption in the before client is happening perfectly, but when it comes to updating the password it loses the encryption. Thanks to anyone who can help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source