From 85ef5958f0e2a78c9497f34d3cd9196c67b6473f Mon Sep 17 00:00:00 2001 From: juancarmore Date: Tue, 27 May 2025 10:42:20 +0200 Subject: [PATCH] frontend: update logout method to include redirection after login --- .../src/lib/interceptors/http.interceptor.ts | 2 +- .../src/lib/services/auth/auth.service.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/projects/shared-meet-components/src/lib/interceptors/http.interceptor.ts b/frontend/projects/shared-meet-components/src/lib/interceptors/http.interceptor.ts index 11d856d..7aa0354 100644 --- a/frontend/projects/shared-meet-components/src/lib/interceptors/http.interceptor.ts +++ b/frontend/projects/shared-meet-components/src/lib/interceptors/http.interceptor.ts @@ -33,7 +33,7 @@ export const httpInterceptor: HttpInterceptorFn = (req: HttpRequest, ne if (!requestUrl.includes('/profile')) { console.log('Logging out...'); const redirectTo = pageUrl.startsWith('/console') ? 'console/login' : 'login'; - authService.logout(redirectTo); + authService.logout(redirectTo, pageUrl); } throw firstError; diff --git a/frontend/projects/shared-meet-components/src/lib/services/auth/auth.service.ts b/frontend/projects/shared-meet-components/src/lib/services/auth/auth.service.ts index 3c2d6b9..ab71e99 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/auth/auth.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/auth/auth.service.ts @@ -32,13 +32,16 @@ export class AuthService { return from(this.httpService.refreshToken()); } - async logout(redirectTo?: string) { + async logout(redirectTo?: string, redirectToAfterLogin?: string) { try { await this.httpService.logout(); this.user = null; if (redirectTo) { - this.router.navigate([redirectTo]); + const queryParams = redirectToAfterLogin + ? { queryParams: { redirectTo: redirectToAfterLogin } } + : undefined; + this.router.navigate([redirectTo], queryParams); } } catch (error) { console.error((error as HttpErrorResponse).error.message); @@ -68,7 +71,7 @@ export class AuthService { } catch (error) { this.user = null; } - + this.hasCheckAuth = true; } }