我正在尝试登录,但以下代码始终返回以下错误,尽管电子邮件和密码正确
身份验证失败!密码错误!
exports.login = (req, res, next) => {
User.findOne({
email: req.body.email
}, (err, user) => {
if (err) throw err;
if (!user) {
res.status(401).json({ authenticated: false, message: 'Email is not registered yet! Please Signup and try Signin' });
} else {
// Check if password matches
user.comparePassword(req.body.password, (err, isMatch) => {
if (!isMatch) return res.status(401).send({ message: 'Authentication failed! Incorrect Password!' });
// Make sure the user has been verified
if (!user.isVerified) return res.status(401).send({ type: 'not-verified', message: 'Your account has not been verified. Please check your email' });
if (isMatch) {
const userInfo = setUserInfo(user);
console.log("userInfo: ", userInfo)
res.status(200).json({
token: `${generateToken(userInfo)}`,
user: userInfo
});
}
});
}
});
};
知道我在做什么错