diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index b51cb58b9..074e4d732 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -73,13 +73,13 @@ export class AuthService { window.location.href = loginUrl; } - logout(): void { + logout(nextUrl?: string): void { this.loaderService.show(); this.actions.clearCurrentUser(); if (isPlatformBrowser(this.platformId)) { this.cookieService.deleteAll(); - window.location.href = `${this.webUrl}/logout/?next=${encodeURIComponent('/')}`; + window.location.href = `${this.webUrl}/logout/?next=${encodeURIComponent(nextUrl || '/')}`; } } diff --git a/src/app/features/settings/profile-settings/components/authenticated-identity/authenticated-identity.component.ts b/src/app/features/settings/profile-settings/components/authenticated-identity/authenticated-identity.component.ts index e3780f0e9..77619339e 100644 --- a/src/app/features/settings/profile-settings/components/authenticated-identity/authenticated-identity.component.ts +++ b/src/app/features/settings/profile-settings/components/authenticated-identity/authenticated-identity.component.ts @@ -11,6 +11,7 @@ import { NgOptimizedImage } from '@angular/common'; import { ChangeDetectionStrategy, Component, computed, inject, OnInit } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; +import { AuthService } from '@core/services/auth.service'; import { ExternalIdentityStatus } from '@osf/shared/enums/external-identity-status.enum'; import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service'; import { LoaderService } from '@osf/shared/services/loader.service'; @@ -31,6 +32,7 @@ import { ProfileSettingsTabOption } from '../../enums'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class AuthenticatedIdentityComponent implements OnInit { + private readonly authService = inject(AuthService); private readonly environment = inject(ENVIRONMENT); private readonly customConfirmationService = inject(CustomConfirmationService); private readonly toastService = inject(ToastService); @@ -85,8 +87,6 @@ export class AuthenticatedIdentityComponent implements OnInit { service: `${webUrl}/login`, next: encodeURIComponent(finalDestination.toString()), }).toString(); - const logoutUrl = new URL(`${webUrl}/logout/`); - logoutUrl.searchParams.set('next', casLoginUrl.toString()); - window.location.href = logoutUrl.toString(); + this.authService.logout(casLoginUrl.toString()); } }