newbie with Passport.js here trying to do a simple thing. I just want to send a custom message to my front-end, im using "passport": "^0.4.0", and "express": "^4.17.0", and "passport-local": "^1.0.0", but i cant seem to get it working. I saw something about this being different with express 4, tried to download connect-flash but didnt manage to get it working.
This sends a message with error normally:
res.status(401).send({
message: 'Authentication key expired'
});
Now im trying to do this with passport strategy, but doesnt seem to send anything to the client but it sends a generic 401 with no custom message:
passport.use(
new LocalStrategy({usernameField: "login", passwordField: "password"}, (login, password, done) => {
User.findByLogin(login).then(async user => {
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
let subscription = await user.getValidSubscription();
if (!subscription) {
return done(null, false, {
message: 'Your subscription has expired.'
});
}
user.dataValues.expiration = subscription.expiration;
return done(null, user);
});
})
);
Again, im aware that this is a problem with flash messages and stuff, but isnt there an easy way out just to send a custom message? All i need is that the 'Incorrect username' reaches my front-end. Ive spent some days into this and still nothing. Thank you in advance!
Edit1: Made it clearer.