Since mongoose 7, findOne no longer accepts a callback. However, the documentation on both the readme of this github and your passport-local strategy page have this example block of code that tries to use a callback. This then fails.
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); }
if (!user.verifyPassword(password)) { return done(null, false); }
return done(null, user);
});
}
));
It needs to be re-written to use promises or async await. I changed it to promises here and this works.
passport.use(
new LocalStrategy(function (username, password, done) {
User.findOne({ username: username })
.then((user) => {
if (!user) {
return done(null, false); // No user found with that username
}
return user.verifyPassword(password).then((isMatch) => {
if (!isMatch) {
return done(null, false); // Password did not match
}
});
return done(null, user); // Successful authentication
})
.catch((err) => {
return done(err); // Error during the process
});
})
Since mongoose 7, findOne no longer accepts a callback. However, the documentation on both the readme of this github and your passport-local strategy page have this example block of code that tries to use a callback. This then fails.
It needs to be re-written to use promises or async await. I changed it to promises here and this works.
Environment