【发布时间】:2013-12-10 23:26:21
【问题描述】:
更新:a commit 修复了以下错误。我已将第一个答案标记为“正确”,尽管该提交在其中一个 cmets 中引起了我的注意
我希望利用自定义回调来处理 Passport 的 authenticate local strategy 中的登录成功和失败,但看起来它只是在成功时调用。
这是我正在谈论的内容的一个sn-p:
passport.use(new LocalStrategy(
{usernameField: 'email', passwordField: 'password'},
function(email, password, done) {
if(canLogin) done(null, user);
else done({message: "This is an error message" }, false, { message: "Some Info" });
}
));
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
// Only called if err is not set
});
知道为什么会这样吗?我的印象是回调会被调用,所以我可以自己处理错误。
【问题讨论】:
标签: javascript node.js express passport.js