没有catch块的异步函数,或者通过拒绝未使用.catch()处理的Promise, 在此代码行中
async(req,email,password,done)=>{
const user = await User.findOne({email:email});
if (!user) {
return done(null, false)
//Err, no email found
}
if (!user.comparePassword(password)) {
return done(null, false);
// Err, pass wrong
}
return done(null, user);
// Login succesfull xd
}
答案 0 :(得分:0)
我想你想做的是...
async function login (email,password) {
try {
const user = await User.findOne({email});
if (!user || !user.comparePassword(password)) {
throw new Error('no user or wrong pass');
}
return user;
// Login succesfull xd
} catch (error) {
// errors including any error thrown by await User.findOne
return null;
}
}