To add Node Express Passport error handling, we use the middleware returned by passport.authenticate
.
For instance, we write
app.post(
"/login",
passport.authenticate("local", {
successRedirect: "/loggedin",
failureRedirect: "/login",
failureFlash: true,
})
);
to call passport.authenticate
to return the authentication middleware.
We use that as the argument of post
to make it use Passport authentication.
We set the successRedirect
and failureRedirect
properties to set the redirect destination in both cases.