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')) {
|
if (!requestUrl.includes('/profile')) {
|
||||||
console.log('Logging out...');
|
console.log('Logging out...');
|
||||||
const redirectTo = pageUrl.startsWith('/console') ? 'console/login' : 'login';
|
const redirectTo = pageUrl.startsWith('/console') ? 'console/login' : 'login';
|
||||||
authService.logout(redirectTo);
|
authService.logout(redirectTo, pageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw firstError;
|
throw firstError;
|
||||||
|
|||||||
@ -32,13 +32,16 @@ export class AuthService {
|
|||||||
return from(this.httpService.refreshToken());
|
return from(this.httpService.refreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout(redirectTo?: string) {
|
async logout(redirectTo?: string, redirectToAfterLogin?: string) {
|
||||||
try {
|
try {
|
||||||
await this.httpService.logout();
|
await this.httpService.logout();
|
||||||
this.user = null;
|
this.user = null;
|
||||||
|
|
||||||
if (redirectTo) {
|
if (redirectTo) {
|
||||||
this.router.navigate([redirectTo]);
|
const queryParams = redirectToAfterLogin
|
||||||
|
? { queryParams: { redirectTo: redirectToAfterLogin } }
|
||||||
|
: undefined;
|
||||||
|
this.router.navigate([redirectTo], queryParams);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error((error as HttpErrorResponse).error.message);
|
console.error((error as HttpErrorResponse).error.message);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user