0
현재 약속의 문제가 있습니다. 내 '자바 스크립트'코드. "TypeError : res.status (...) .json (...). catch는 함수가 아닙니다."던지며 코드의 어딘가에서 내 약속이 잘못되었다고 생각합니다. 'UnhandledPromiseRejection'경고 : 처리되지 않은 약속 거부 (거부 ID : 2) : TypeError : res.status (...). json (...). catch가 함수가 아닙니다.
이
내가 지금까지 무엇을 가지고 :route.js
route.post('/login', function(req, res) {
log.login(req,res).then((post)=>{
res.status(200).json({message: post})
.catch((error)=>{
res.status(400).json({message: error})
})
})
});
내가 방금 })
, 고정 코드를 놓친 있다고 생각
function login(req,res){
console.log('here', req.body.email, req.body.password)
if (!req.body.email || !req.body.password) {
return Promise.resolve({success: false, msg: 'Please pass email and password.'});
} else {
return Promise.resolve(User.findOne({
'local.email': req.body.email
})).exec().then((user)=> {
if (!user) {
return Promise.reject({success:false, msg: 'Authentication failed. User not found'}); //res.send({success: false, msg: 'Authentication failed. User not found.'});
} else {
// check if password matches
if(user.validPassword(req.body.password)) {
// if user is found and password is right create a token
var token = jwt.sign(user.id, config.secret);
// return the information including token as JSON
return Promise.resolve({success: true, token: 'JWT ' + token});
} else {
return Promise.reject({success: false, msg: 'Authentication failed. Wrong password.'});
}
}
}).catch((errors)=>{
return ({message: "Could not propose login"});
})
}
}
module.exports = {
login
}