From c2b2753943d59a6b4b5149f1003371338ac1a210 Mon Sep 17 00:00:00 2001 From: Chaz Gatian Date: Thu, 5 Nov 2020 12:29:44 -0500 Subject: [PATCH] fix: clear location.hash only if it is present address issues with firefox and Angular router Closes #970 --- projects/lib/src/oauth-service.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 6f0bce0f..2909f6b4 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -1893,7 +1893,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { if (!this.oidc) { this.eventsSubject.next(new OAuthSuccessEvent('token_received')); if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) { - location.hash = ''; + this.clearLocationHash(); } this.callOnTokenReceivedIfExists(options); @@ -1918,7 +1918,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { this.storeIdToken(result); this.storeSessionState(sessionState); if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) { - location.hash = ''; + this.clearLocationHash(); } this.eventsSubject.next(new OAuthSuccessEvent('token_received')); this.callOnTokenReceivedIfExists(options); @@ -1989,7 +1989,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { options.onLoginError(parts); } if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) { - location.hash = ''; + this.clearLocationHash(); } } @@ -2695,4 +2695,15 @@ export class OAuthService extends AuthConfig implements OnDestroy { ); }); } + + /** + * Clear location.hash if it's present + */ + private clearLocationHash() { + // Checking for empty hash is necessary for Firefox + // as setting an empty hash to an empty string adds # to the URL + if(location.hash != '') { + location.hash = ''; + } + } }