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.
Asked
Active
Viewed 775 times
2 Answers
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