Answer the question
In order to leave comments, you need to log in
Why doesn't passport js accept the correct username and password?
There is this code
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
}, function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
console.log(username, password)
return err ?
done(err) :
user ?
password === user.password ?
done(null, user) :
done(null, false, { message: 'Incorrect password.' }) :
done(null, false, { message: 'Incorrect username.' });
});
}));
app.post('/logins', function(req, res, next) {
passport.authenticate('local',
function(err, user, info) {
console.log(err, user, info)
return err ?
next(err) :
user ?
req.logIn(user, function(err) {
return err ?
next(err) :
res.redirect('/admin');
}) :
res.redirect('/login');
}
)(req, res, next);
});
Answer the question
In order to leave comments, you need to log in
Check your POST request for a Content-Type header.
Should be: application/x-www-form-urlencoded.
Otherwise, it won't even reach the callback.
There was such a problem with passport, perhaps your case
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question