I'm using the Angular-Fullstack yeoman generator as the basis for my project: https://github.com/DaftMonk/generator-angular-fullstack
I cannot figure out how to redirect users to the link they originally requested after logging in.
Example of what I want to happen:
- Unauthenticated user requests http://myapp/videos/video1
- User is directed to log in
- User successfully authenticates
- User is automatically redirected to http://myapp/videos/video1
I am using both the boilerplate local login and boilerplate OAuth.
Thanks for any help!
What I did in a similar case, is that when I redirected user to login page, I attached to the url (as a query parameter) the initial path that user was trying to access eg.
path_to_login?requested_url=/videos/video1
. So when the login was completed successfully I just readrequested_url
query parameter and if that existed, user was redirected to the specified path.I figured it out, here are the steps I took to solve this problem.
For some reason, Stack Overflow isn't formatting my last 2 code blocks below.I made a gist with the code below (note 3 separate files need to be modified) https://gist.github.com/dcoffey3296/d27c141ef79bec3ff6a6store the url to return to in a cookie within the
.run()
method ofclient/app/app.js
for Oauth, check for this cookie and redirect if it exists in
server/auth/auth.service.js
for local login, check for cookie in the
.then()
part of$scope.login()
, file:client/app/account/login/login.controller.js