Thursday, 15 July 2010

sails.js - How to redirect to last action in sailsjs using req.session? -


I am creating a login application, where I need to go back to the previous URL from where the login action says. I want to know that Sail provides an inherent method of using which I can redirect to the previous action without making my support function.

If you fail the user to authenticate and require a login,

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

The above line ensures that they are receiving a request because something else provides another layer of complexity.

Then you can check that person after logging in and re-route

  if (req.session.afterLoginGoTo) res.redirect back ( Req.Session.afterLoginGoTo); Else res.redirect ('/ defaultHomePage');  

No comments:

Post a Comment