I have a few questions regarding how passport.js works. On it's documentation theres an axample:
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
And from this article I read:
Calling done will make the flow jump back into passport.authenticate. It's passed the error, user and additional info object (if defined).
So the questions are (and hope they make sense):
- Where is the done function defined?
- How when and where is it passed as an argument to function(username, password, done)?
- How is passport.use(new LocalStrategy()) connected to passport.authenticate? The quotation says one call the other, but I can't see where that is happening
Thanks!