Skip to content

Commit

Permalink
Streamline session invalidation to fix logout redirection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
boehlke committed Oct 7, 2024
1 parent 0317386 commit 83a44a1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions client/src/app/site/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class AuthService {

private readonly _logoutEvent = new EventEmitter<void>();
private readonly _loginEvent = new EventEmitter<void>();
private _invalidateSessionAfterPromise: Promise<void> | null = null;

public constructor(
private lifecycleService: LifecycleService,
Expand Down Expand Up @@ -108,19 +109,22 @@ export class AuthService {
}
}

public async invalidateSessionAfter(callback?: () => Promise<any>): Promise<void> {
private async _invalidateSessionAfter(callback?: () => Promise<any>): Promise<void> {
try {
const response = callback ? await callback() : {success: true};
const response = callback ? await callback() : { success: true };
console.debug(`auth: Invalidate session after`, response);
if (response?.success) {
this.authTokenService.setRawAccessToken(null);
this._logoutEvent.emit();
// sessionStorage.clear();
await this.sharedWorker.sendMessage(<AuthUpdateMessage>{
receiver: `auth`,
msg: { action: `update`, params: null }
});
this.DS.deleteCollections(...this.DS.getCollections());
await this.DS.clear();
this.lifecycleService.bootup();
this.oauthService.logOut();
}
} catch (e) {
this.sharedWorker.sendMessage(<AuthUpdateMessage>{
Expand All @@ -131,6 +135,14 @@ export class AuthService {
}
}

public async invalidateSessionAfter(callback?: () => Promise<any>): Promise<void> {
if (this._invalidateSessionAfterPromise) {
return this._invalidateSessionAfterPromise;
}
this._invalidateSessionAfterPromise = this._invalidateSessionAfter(callback);
return this._invalidateSessionAfterPromise;
}

public async logout(): Promise<void> {
this.lifecycleService.shutdown();
this.authTokenService.setRawAccessToken(null);
Expand Down Expand Up @@ -176,7 +188,7 @@ export class AuthService {
await this.oauthService.loadDiscoveryDocumentAndLogin();
this.oauthService.setupAutomaticSilentRefresh();
this.allowRefreshTokenAndSilentRefreshOnMultipleTabs();
if(this.oauthService.getAccessToken()) {
if (this.oauthService.getAccessToken()) {
this.propergateToken();
}
}
Expand Down Expand Up @@ -246,7 +258,7 @@ export class AuthService {
}
}

private propergateToken() {
private propergateToken(): void {
this.authTokenService.setRawAccessToken(this.oauthService.getAccessToken());
this.sharedWorker.sendMessage(<AuthUpdateMessage>{
receiver: `auth`,
Expand Down

0 comments on commit 83a44a1

Please sign in to comment.