javascript - 对象:空原型不允许检索值
问题描述
尝试比较密码时出现此错误
UnhandledPromiseRejectionWarning:错误:需要数据和哈希参数
事情是 user.password 返回未定义,但是当我执行 console.log(user) 它返回模型
像这样
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
护照.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
。
推荐阅读
- python - Python 正则表达式捕获 Verilog 端口名称
- html - 嵌套内部元素的样式:未应用已访问声明(vuejs,sass)
- c# - 无法加载程序集文件
- javascript - 如何更改每个 html 表格行手风琴
- kubernetes - Kubernetes 中的 Gitlab Runner 无法解析主机
- mongodb - 无法使用 Go 驱动程序连接到未初始化的副本集
- python - 是否可以将函数定义为变量?
- r - SuperLearner 用于 R 中的生存结果
- git - 在 ansible-pull 命令中使用托管在 S3 上的 Git 存储库而不是 Github/Stash
- liferay - 如何在 Liferay 7.1 的 jsp 中嵌入导航 portlet?