frontend: update logout method to include redirection after login
This commit is contained in:
parent
e1a6bccbcb
commit
85ef5958f0
@ -33,7 +33,7 @@ export const httpInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, 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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user