i tried to find a solution everywhere and had no luck.
I have the Route on my nodejs api app like:
app.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile',
failureRedirect: '/login',
failureFlash: true
}));
Then, on my passport strategy like this:
passport.use('local-login', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
},
function (req, email, password, done) {
User.findOne({ 'local.email': email }, function (err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(null, false, req.flash('LoginMessage', 'No User Found!'));
}
if (user.local.password != password) {
return done(null, false, req.flash('LoginMessage', 'Wrong Password!'));
} else {
return done(null, user);
}
})
}
));
What i need, is to receive the message as a json return on my route, so i can access it with external apps using Angularjs or anything else. so the output would be something like:
{
"message": "User Not Found!"
}
How can i solve this problem?