I set up the password field like below:
password: {
type: Sequelize.STRING,
validate: {
len: {
args: [7, 42],
msg: "The password length should be between 7 and 42 characters."
}
}
}
This works. However, when I add the set handler, to convert the password into an md5 hash, the validation fails always (it ends with that message I set up above):
password: {
type: Sequelize.STRING,
validate: {
len: {
args: [7, 42],
msg: "The password length should be between 7 and 42 characters."
}
},
set (pass, key) {
// `key` is "password" here
this.setDataValue(key, md5(pass));
}
}
It seems to me like len and set don't like each another, but I can't understand why.
How to solve this?