【发布时间】:2015-01-07 10:12:02
【问题描述】:
我正在使用护照本地策略验证我的 nodeJs 应用程序。一切正常。但是我怎样才能向用户显示他输入了无效的登录凭据的适当消息。我目前的代码只是在屏幕上发送401未授权错误。
这是我的代码
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
});
【问题讨论】:
标签: node.js express passport.js