From 2bdcfaeb95a397b920f8a2a9beb98b125c995948 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 7 Nov 2023 10:48:29 +0100 Subject: [PATCH] fix: prevent logout when the user was already logout --- .../api-rest-interceptor.service.spec.ts | 1 + .../api-rest-interceptor/api-rest-interceptor.service.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.spec.ts b/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.spec.ts index 9311de7eb..71f02c60a 100644 --- a/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.spec.ts +++ b/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.spec.ts @@ -125,6 +125,7 @@ describe('ApiRestInterceptor', () => { const authService = spectator.inject(AuthService); authService.getAuth.mockReturnValue({ token, refresh }); + authService.isLogged.mockReturnValue(true); const authInterceptorService = spectator.inject(ApiRestInterceptorService); const apiRequest = new HttpRequest('GET', ConfigServiceMock.apiUrl); diff --git a/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.ts b/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.ts index a66949821..4e73b83cb 100644 --- a/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.ts +++ b/javascript/apps/taiga/src/app/shared/api-rest-interceptor/api-rest-interceptor.service.ts @@ -78,7 +78,10 @@ export class ApiRestInterceptorService implements HttpInterceptor { (!auth?.token || !auth?.refresh) && !request.url.includes('/auth/token') ) { - void this.router.navigate(['/logout']); + if (this.authService.isLogged()) { + void this.router.navigate(['/logout']); + } + return EMPTY; } } @@ -145,7 +148,9 @@ export class ApiRestInterceptorService implements HttpInterceptor { catchError((err: HttpErrorResponse) => { this.refreshTokenInProgress = false; - void this.router.navigate(['/logout']); + if (this.authService.isLogged()) { + void this.router.navigate(['/logout']); + } return throwError(() => err); })