Reputation: 15684
Trying to understand https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js , at line 57.
I dont understand why the passport authenticate method has 4 arguments :
module.exports = function authenticate(passport, name, options, callback){/*code*/}
In practice it's used like this:
passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' });
or
passport.authenticate('local', function(req, res));
So how come the first argument "passport" in the method définition is not interfering ? Since the strategy name is passed as first argument, it should be mapped to passport not to name.
Upvotes: 0
Views: 142
Reputation: 203286
You missed an intermediate layer here:
Authenticator.prototype.authenticate = function(strategy, options, callback) {
return this._framework.authenticate(this, strategy, options, callback);
};
The passport
variable is an instance of the Authenticator
class, so the method above represents passport.authenticate()
. As you can see, it passed a reference to itself as first argument to the function that you're referring to (which is referred to by this._framework.authenticate
).
Upvotes: 3