0

I am creating a login application where I need to redirect back to previous url from where the login action was called. I need to know does sails provide a built-in method by using which I can redirect to previous action without creating my own helper function.

Rohit Choudhary
  • 2,253
  • 1
  • 23
  • 34

2 Answers2

1

You can put this line in your policy if the users fails authentication and requires a login

if(req.method.toLowerCase() === 'get') req.session.afterLoginGoTo = req.originalUrl;

The above line makes sure they are doing a GET request as anything else provides another layer of complexity.

Then after you log the person in you can check for that and re-route

if(req.session.afterLoginGoTo) return res.redirect(req.session.afterLoginGoTo);
else res.redirect('/defaultHomePage');
Meeker
  • 5,979
  • 2
  • 20
  • 38
0

Just get the origin request from req and then use res.redirect()

dkx22
  • 1,103
  • 1
  • 13
  • 25