Impossible to redirect to previous page after logging in
See original GitHub issueHello!
I am using this library for an oauth protected application. Using an auth-guard, the secured pages trigger a login page which calls an authservice configured as in the code snippet.
Somehow it seems impossible to redirect to the chosen page after logging in, as only one redirect can be set. Anyone an idea how to configure it? Listening to the event “token_received” does not seem to work.
export class AuthService {
constructor(
private router: Router,
private oauthService: OAuthService
) {
this.oauthService.configure(authConfig);
this.oauthService.setupAutomaticSilentRefresh();
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.tryLogin({});
}
login() {
this.oauthService.initImplicitFlow();
}
}```
Issue Analytics
- State:
- Created 5 years ago
- Comments:18
Top Results From Across the Web
redirect user to previous page after login - php - Stack Overflow
You should first get user refer page in a variable using $_SERVER['HTTP_REFERER']; in your login page.
Read more >How to redirect users back to previous page, after logging in?
This can be done by specifying a Return URL in the form URL by providing a value to Source querystring. For example:.
Read more >Redirect to previous page after login - WordPress.org
I want visitor to remain on the same page after login or register. Is it possible to accomplish by any hook? The page...
Read more >Login redirect to previous page - Auth0 Community
Unfortunately rules can't do this for you. Rules execute on the server side of Auth0 and by the time wordpress redirects you away...
Read more >After Login Redirect To Previous Page In WordPress
Sometimes, It is required to redirect users back to the page they were viewing before logging in. There could be a plugin for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ggjersund I’ve had similar issue, while trying to redirect user back to requested url on
onTokenReceived
event. Fixed it by settingclearHashAfterLogin
setting to false, therefore the router is not triggered onlocation.hash = '';
, so thatthis.router.navigateByUrl
works correctly.I’m using the same library, and in my production application I have a flow similar to what you describe (which I documented in a toy-problem version in a sample repo). It’s still on my to do list to add the feature you describe (navigate to the intended page after getting back from the ID Server, right?) to my production application, but I have played around with it a bit.
I also found that responding to events like you mention does not work for this feature. I’m guessing the implementation of state upon returning is lagging behind the library’s move towards events. But that’s a guess.
As for a solution, I found that this can work:
Send the intended url along with the user when they go to the ID Server (you might need to do this in the auth guard based on the target URL instead of the current URL):
PS. The
encodeURIComponent
is because of #415 (e.g.?
characters get lost otherwise).Then when the user gets back you cannot use the event as you noted, but I found that this does work:
Edit: see updated/improved solution below.
Hope that helps.