了解Passportjs自定义回调 [英] Understanding Passportjs Custom Callback
问题描述
我正在尝试使用Passportjs并且自定义回调的代码是:
I'm experimenting with Passportjs and the code for a Custom Callback is:
app.get('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err); }
if (!user) { return res.redirect('/login'); }
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + user.username);
});
})(req, res, next);
});
我对所有这些代码感到满意,除了倒数第二行(req,res,next);
- 有人可以解释为什么在最后添加这些参数。这可能是一个JS问题,而不是Passport问题,但是非常感谢任何帮助。
I'm happy with all of this code except for the second to last line (req, res, next);
- Could someone explain why these parameters are added on the end. This is probably more of a JS question than a Passport question but any help is much appreciated.
推荐答案
javascript答案是它返回一个用第二组参数再次调用的函数。
The "javascript" answer is that it returns a function which is called again with those 2nd set of arguments.
该函数是链中每个策略失败的累加器。
That function is the "accumulator for failures from each strategy in the chain".
https://github.com/jaredhanson/passport/blob/master/lib/middleware /authenticate.js
这篇关于了解Passportjs自定义回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!