[英]"TypeError: Cannot read property 'status' of undefined" node.js
我正在嘗試使用 nodejs express.js sequelize 創建一個返回令牌的函數,但出現此錯誤“類型錯誤:無法讀取未定義的屬性‘狀態’”
exports.login = (data)=>{
return user.findOne({
where : {userName: data.userName}
}).then(userFound => {
if (userFound){
bcrypt.compare(data.password,userFound.password,(errBcrypt,resBcrypt)=>{
if(resBcrypt) {
return {
status : 201,
token : jwt.sign({id: user.id},secretCode,{expiresIn:'1h'})
};
}else {
return {
status : 403,
errBcrypt : 'password invalid!'
};
}
})
}else{
return {
status : 403,
error : 'user not exist!'
};
}
})
.catch((err) =>{
return {
status : 403,
error : err
};
});
}
是控制器功能還是它在哪里使用,也嘗試返回一個承諾
exports.login = (data)=>{
return new Promise((resolve,reject)=>{
user.findOne({
where : {userName: data.userName}
}).then(userFound => {
if (userFound){
bcrypt.compare(data.password,userFound.password,(errBcrypt,resBcrypt)=>{
if(resBcrypt) {
return resolve({
status : 201,
token : jwt.sign({id: user.id},secretCode,{expiresIn:'1h'})
})
}else {
return resolve({
status : 403,
errBcrypt : 'password invalid!'
})
}
})
}else{
return resolve({
status : 403,
error : 'user not exist!'
})
}
})
.catch((err) =>{
return reject({
status : 403,
error : err
})
});
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.