fix(ui): logout needs access token before clearing session (#2340)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user