Skip to content

Commit c2b2753

Browse files
author
Chaz Gatian
committed
fix: clear location.hash only if it is present
address issues with firefox and Angular router Closes manfredsteyer#970
1 parent 8d152c2 commit c2b2753

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

projects/lib/src/oauth-service.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
18931893
if (!this.oidc) {
18941894
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
18951895
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
1896-
location.hash = '';
1896+
this.clearLocationHash();
18971897
}
18981898

18991899
this.callOnTokenReceivedIfExists(options);
@@ -1918,7 +1918,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
19181918
this.storeIdToken(result);
19191919
this.storeSessionState(sessionState);
19201920
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
1921-
location.hash = '';
1921+
this.clearLocationHash();
19221922
}
19231923
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
19241924
this.callOnTokenReceivedIfExists(options);
@@ -1989,7 +1989,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
19891989
options.onLoginError(parts);
19901990
}
19911991
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
1992-
location.hash = '';
1992+
this.clearLocationHash();
19931993
}
19941994
}
19951995

@@ -2695,4 +2695,15 @@ export class OAuthService extends AuthConfig implements OnDestroy {
26952695
);
26962696
});
26972697
}
2698+
2699+
/**
2700+
* Clear location.hash if it's present
2701+
*/
2702+
private clearLocationHash() {
2703+
// Checking for empty hash is necessary for Firefox
2704+
// as setting an empty hash to an empty string adds # to the URL
2705+
if(location.hash != '') {
2706+
location.hash = '';
2707+
}
2708+
}
26982709
}

0 commit comments

Comments
 (0)