I would like to get the passport-local-mongoose specific error message after a failed login attempt. Are they connect-flash messages? I have tried this
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) { return res.send(info); }
if (!user) { return res.send(info); }
req.logIn(user, function(err) {
if (err) { return res.send(info); }
return res.send(user.username);
});
})(req, res, next);
});
But then I will get passportJS error messages like "Missing credentials". I would like to get the incorrectPasswordError or incorrectUsernameError, just returned in plain json. I use client side templating, so redirection is made on the client. How can I access the error messages?