本文共 843 字,大约阅读时间需要 2 分钟。
我正在使用护照本地策略验证我的 nodeJs 应用程序 . 一切都很好 . 但是,如何向用户显示他输入的相应消息 invalid login credentials . 我现在的代码只是在屏幕上发送 401 unauthorized error .
这是我的代码
passport.use(new LocalStrategy(function(username, password, callback) {
User.findOne({
username : username
}, function(err, user) {
if (err) {
return callback(err);
}
// No user found with that username
if (!user) {
return callback(null, false);
}
// Make sure the password is correct
user.verifyPassword(password, function(err, isMatch) {
if (err) {
return callback(err);
}
// Password did not match
if (!isMatch) {
return callback(null, false);
}
// Success
return callback(null, user);
});
});
}));
exports.isLocalAuthenticated = passport.authenticate('local', {
session : true
});
router.post('/', authController.isLocalAuthenticated, function(req, res) {
//here I want to show the error message to user
});
转载地址:https://blog.csdn.net/weixin_34262786/article/details/114189572 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!