How to redirect to a cutom page on a (example database) error, and display the message, when using passport-local. here's the code:
passport.use(new LocalStrategy({
passReqToCallback: true
}, function( req, username, password, done ) {
done({error:'mycustomerrormessage'});
}
));
the routing looks like:
app.post('/auth/local', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/',
failureFlash: true
}));
when the error occurs, the url stay /auth/local, with a nasty [object Object] content.
if I call
done( null, false, { message: "error message"})
than passport redirects to /, and I can flash the message, but how can I set a redirection in case I call the verify function with a first not null parameter and do something with that error?
based on express documentation, you can configure error handling middleware as following:
app.use(function(err, req, res, next){
console.error(err.stack);
res.send(500, 'Something broke!');
});
The four parameter signature indicates that this is an error handling definition.