Using BCrypt with Sequelize Model

前端 未结 3 1047
礼貌的吻别
礼貌的吻别 2020-12-05 10:47

I\'m trying to use the bcrypt-nodejs package with my sequelize model and was tring to follow a tutorial to incorporate the hashing into my model, but I\'m getti

3条回答
  •  清歌不尽
    2020-12-05 11:15

    Other alternative: Use hook and bcrypt async mode

    User.beforeCreate((user, options) => {
    
        return bcrypt.hash(user.password, 10)
            .then(hash => {
                user.password = hash;
            })
            .catch(err => { 
                throw new Error(); 
            });
    });
    

提交回复
热议问题