Javascript 对象:空原型不允许检索值
我在尝试比较密码时遇到此错误 未处理的PromisejectionWarning:错误:数据和散列参数 必需的 问题是user.password返回未定义的,但是当我执行console.log(user)时,它返回模型 像这样Javascript 对象:空原型不允许检索值,javascript,node.js,express,passport.js,bcrypt,Javascript,Node.js,Express,Passport.js,Bcrypt,我在尝试比较密码时遇到此错误 未处理的PromisejectionWarning:错误:数据和散列参数 必需的 问题是user.password返回未定义的,但是当我执行console.log(user)时,它返回模型 像这样 ModelBase { attributes: [Object: null prototype] { username: 'billy', id: 4, password: '$2b$12$oIIn*******AnNk
ModelBase {
attributes:
[Object: null prototype] {
username: 'billy',
id: 4,
password:
'$2b$12$oIIn*******AnNkr/Pt89S****W3Vi2o8DYBgnEy9t9gcje',
email: 'exampleman@example.com',
created_at: 2019-05-28T20:00:37.164Z,
updated_at: 2019-05-28T20:00:37.164Z },
所以我不明白为什么我在做user.password
passport.js
.......
passport.use('login',
new Local(
{
usernameField:'username',
passwordField:'password',
session:false
},
(username, password, done, req) => {
try{
User.forge({username: username}).fetch()
.then(user => {
if(user === null){
return done(null, false, {message: 'Username doesn\'t exist'})
}
else{
console.log(user); // logs out user model along with password info
// not getting user.password from user model.
bcrypt.compare(password, user.password)
.then(response => {
if(response !== true){
console.log('passwords do not match');
return done(null, false, {message:'passwords do not match'} )
}
console.log('user found & authenticated');
return done(null, user);
})
}
})
}catch(err){
done(err);
}
}
))
尝试与
user.attributes.password
进行比较