diff --git a/frontend/src/app/shared/service/auth.service.spec.ts b/frontend/src/app/shared/service/auth.service.spec.ts index 763b813bd..f09dcd45c 100644 --- a/frontend/src/app/shared/service/auth.service.spec.ts +++ b/frontend/src/app/shared/service/auth.service.spec.ts @@ -185,8 +185,8 @@ describe('AuthService', () => { const logoutRequest = httpTestingController.expectOne(`${API_CONFIG.BASE_URL}/api/v1/auth/logout`); expect(logoutRequest.request.body).toEqual({ refreshToken: 'refresh-token' }); - refreshRequest.flush({ accessToken: 'late-access', refreshToken: 'late-refresh' }); logoutRequest.flush({ logoutUrl: null }); + refreshRequest.flush({ accessToken: 'late-access', refreshToken: 'late-refresh' }); await expect(refresh).rejects.toThrow('Refresh response belongs to a stale session'); expect(service.getInternalAccessToken()).toBeNull(); diff --git a/frontend/src/app/shared/service/auth.service.ts b/frontend/src/app/shared/service/auth.service.ts index 1ccfa663a..e80d00e69 100644 --- a/frontend/src/app/shared/service/auth.service.ts +++ b/frontend/src/app/shared/service/auth.service.ts @@ -177,14 +177,14 @@ export class AuthService { this._logoutInProgress.set(true); const refreshToken = this.getInternalRefreshToken(); - this.clearSession(); - this.http.post<{ logoutUrl: string | null }>(`${this.apiUrl}/logout`, { refreshToken }) .pipe(finalize(() => { this._logoutInProgress.set(false); })) .subscribe({ next: (response) => { + this.clearSession(); + if (response.logoutUrl) { this.redirectTo(response.logoutUrl, true); } else { @@ -192,6 +192,8 @@ export class AuthService { } }, error: () => { + this.clearSession(); + this.redirectTo('/login', true); } });