I am just getting my head round Passport in Node
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);
});
}
));
This is all great, I understand the logic. However I don't understand where variables User from
User.findOne({ username:....
Is coming from? This isn't set anywhere and baffles me a little.
The example is using a mongoose model (User) that was defined elsewhere. Mongoose models have a findOne function. It's meant to mostly be filler to show how you would use the strategy to lookup info in the db to authenticate the user.