Skip to content

Commit

Permalink
fix: clear location.hash only if it is present
Browse files Browse the repository at this point in the history
address issues with firefox and Angular router

Closes #970
  • Loading branch information
Chaz Gatian committed Nov 5, 2020
1 parent 8d152c2 commit c2b2753
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1989,7 +1989,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
options.onLoginError(parts);
}
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
location.hash = '';
this.clearLocationHash();
}
}

Expand Down Expand Up @@ -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 = '';
}
}
}

0 comments on commit c2b2753

Please sign in to comment.