Search code examples
angularjssatellizer

angularjs satellizer redirect back to previous page


I am using satellizer in my angular code to handle my authentication with local api. I am not integrating any third party API authentication with my site, everything is local. I get the website working, if the user is with invalid token, system will redirect the user to login page. What if I need to bring the requested link back after the user login, how do I do that?

for example. If the user request to access '/customer/detail/123', but user is redirected to the login page (/account/login), after the login is successful, how could I redirect the user back to '/customer/detail/123'


Solution

  • Satellizer is not helping you with this problem. I also ran into this and created a service to handle this. So if a user is redirected to /login, I save the path in a service. After login, redirect to the saved path by getting it out of the service.

    1. When using ui-router, detect every change by listening to '$stateChangeStart'. When the state changes and a login is needed, save the current path by getting it from: '$location.path()'

    2. After login, set the path to $location.path();

    Hope this helps. Lieuwe