diff --git a/booklore-ui/src/app/shared/components/login/login.component.ts b/booklore-ui/src/app/shared/components/login/login.component.ts index 9b3500f9a..283c9f596 100644 --- a/booklore-ui/src/app/shared/components/login/login.component.ts +++ b/booklore-ui/src/app/shared/components/login/login.component.ts @@ -54,6 +54,8 @@ export class LoginComponent implements OnInit { private static readonly MAX_REDIRECT_COUNT = 3; ngOnInit(): void { + this.authService.clearSessionOnLoginPage(); + this.route.queryParams.pipe(take(1)).subscribe(params => { if (params['reason'] === 'session_revoked') { this.infoMessage = this.translocoService.translate('auth.login.sessionRevoked'); diff --git a/booklore-ui/src/app/shared/service/auth.service.ts b/booklore-ui/src/app/shared/service/auth.service.ts index d13524db5..8de008081 100644 --- a/booklore-ui/src/app/shared/service/auth.service.ts +++ b/booklore-ui/src/app/shared/service/auth.service.ts @@ -77,10 +77,10 @@ export class AuthService { const refreshToken = this.getInternalRefreshToken(); this.http.post<{ logoutUrl: string | null }>(`${this.apiUrl}/logout`, {refreshToken}).subscribe({ next: (response) => { - this.clearSession(); if (response.logoutUrl) { window.location.href = response.logoutUrl; } else { + this.clearSession(); this.router.navigate(['/login']).then(() => window.location.reload()); } }, @@ -96,6 +96,10 @@ export class AuthService { this.router.navigate(['/login'], {queryParams: {reason}}); } + clearSessionOnLoginPage(): void { + this.clearSession(); + } + private clearSession(): void { localStorage.removeItem('accessToken_Internal'); localStorage.removeItem('refreshToken_Internal');