Skip to content

Commit

Permalink
fix: prevent logout when the user was already logout
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Nov 7, 2023
1 parent 982e12b commit 2bdcfae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
})
Expand Down

0 comments on commit 2bdcfae

Please sign in to comment.