I'm trying to make the data update encrypt the user's password, but it simply does not work and does not give an error. Have the following sequelize model.
import bcrypt from 'bcrypt';
export default (sequelize, DataType) => {
const Users = sequelize.define('Users', {
id: {
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataType.STRING,
allowNull: false,
validation: {
notEmpty: true,
},
},
jobTitle: {
type: DataType.STRING,
allowNull: false,
validation: {
notEmpty: true,
},
},
login:{
type:DataType.INTEGER,
allowNull:false,
validation:{
notEmpty:true
}
},
password:{
type:DataType.STRING,
allowNull:false,
validation:{
notEmpty:true
},
},
},
{
hooks:{
beforeCreate: user => {
const salt = bcrypt.genSaltSync();
user.set('password', bcrypt.hashSync(user.password, salt))
},
beforeUpdate: user => {
const salt = bcrypt.genSaltSync();
user.set('password', bcrypt.hashSync(user.password, salt))
},
},
classMethods:{
isPassword:(encodedPassword, password) => bcrypt.compareSync(password, encodedPassword)
}
});
return Users;
}
create works perfectly, however in the update nor does it perform the update.