PassportJS and redirects

When a user visits my site, they can visit some partial files without having to login. If they log in (via modal), the passport data redirects them back to the main page. If I remove the call forwarding, the passport is unable to fully login.

Does anyone have some code they can use that bypasses the required redirect or redirects the user to the current url they are on (without redirecting to '/')?

Below is my code that calls passport then does the "required" redirect:

app.post('/login', passport.authenticate('local-login', {
    successRedirect : '/', 
    failureRedirect : '/', 
    failureFlash : true 
}));

      

+3


source to share


1 answer


Yah - you don't need to redirect when authenticating - see example below:



app.post('/login',
  passport.authenticate('local'),
  function(req, res) {
    // If this function gets called, authentication was successful.
    // `req.user` contains the authenticated user.
    res.redirect('/users/' + req.user.username);
  });
);

      

+3


source







All Articles