1
키워드 this
을 사용하여 사용자 인스턴스에 저장된 암호에 액세스하려고하는데 작동하지 않습니까?Sequelize 인스턴스 메소드가 작동하지 않습니까?
여기 내가 코드를 호출 할 때의 코드입니다.
Users.find({where: {$or: [{ email: email} ,{ username: username }]}})
.then(user => {
if (!user) return res.status(401).send(new errors.Unauthorized('Email/Username or Password Not Found!'));
user.authenticate(password, (err, match) => {
if (err) return res.status(401).send(err);
res.send(user);
});
})
.catch(err => res.send(err));
다음은 내 인스턴스 메소드 코드입니다.
instanceMethods :{
authenticate: (password, cb) => {
return bcrypt.compare(password, this.password, (err, match) => {
if (err) return cb(new errors.Unauthorized());
return cb(null, match);
});
}
}