fix(ui): logout needs access token before clearing session (#2340)

This commit is contained in:
James Ward
2026-08-23 09:58:32 -06:00
committed by GitHub
parent f8c45da98a
commit bc5616f414
2 changed files with 5 additions and 3 deletions
@@ -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();
@@ -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);
}
});