0

When entering the correct login info, it does nothing. No error logs or redirect.

router.post("/login", (req, res, next) => {
  passport.authenticate(
    "local",
    { successRedirect: "/dashboard" },
    (err, user, done) => {
      if (!user) {
        return res.json(done);    //sends error msg ("email not registered", "password incorrect", etc.)
      }
    }
  )(req, res, next);
});

What could be the issue for this?

wzrd
  • 55
  • 1
  • 4

1 Answers1

0

passport.authenticate accept 2 parameters. If you choose custom callback, then removing { successRedirect: "/dashboard" }. Code example:

app.get('/login', function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
    if (err) { return next(err); }
    if (!user) { return res.redirect('/login'); }
    req.logIn(user, function(err) {
      if (err) { return next(err); }
      return res.redirect('/users/' + user.username);
    });
  })(req, res, next);
});
Phan Việt
  • 1,253
  • 11
  • 11