How to display login errors from Passport on front end?

Hi everyone, I have a project up that uses passport, passport-local, and passport-local-mongoose for user authentication. It seems like visitors can sign up and login successfully, and if there are any errors (like an existing username or wrong password), they are redirected back to the sign up / login page to try again. However, I’m having a hard time figuring out how to display the errors on the front end. Is there a way to send this info from the server to the client, so that I can show them on the front end?

Here is a link to the project:


And how the sign up and log in code are set up in my auth.js file:

passport.use(new LocalStrategy(User.authenticate()));
...'/login/password', passport.authenticate('local', {
    successRedirect: '/home.html',
    failureRedirect: '/login.html'
}), function(req, res, next) {
);'/signup', function(req, res, done) {
    User.register(new User({ username: req.body.username }), req.body.password, function (err, user) {
        if (err) {
            console.log(`There was an error signing up: ${err}`);
            return res.redirect('/signup.html');
        passport.authenticate('local') (req, res, function() {

Any help with this would be appreciated! Thanks all.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.