From d8ee1f55f170cc21c6d73f12e18036e2a704b88d Mon Sep 17 00:00:00 2001 From: Michael Spalti Date: Thu, 6 Apr 2023 09:26:36 -0700 Subject: [PATCH] closing auth check subscription --- src/modules/app/browser-init.service.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modules/app/browser-init.service.ts b/src/modules/app/browser-init.service.ts index a1b41c8ea2..f5b48fd902 100644 --- a/src/modules/app/browser-init.service.ts +++ b/src/modules/app/browser-init.service.ts @@ -31,12 +31,16 @@ import { isNotEmpty } from '../../app/shared/empty.util'; import { logStartupMessage } from '../../../startup-message'; import { MenuService } from '../../app/shared/menu/menu.service'; import { RootDataService } from '../../app/core/data/root-data.service'; +import { firstValueFrom, Subscription } from 'rxjs'; /** * Performs client-side initialization. */ @Injectable() export class BrowserInitService extends InitService { + + sub: Subscription; + constructor( protected store: Store, protected correlationIdService: CorrelationIdService, @@ -139,13 +143,13 @@ export class BrowserInitService extends InitService { } /** - * During the external authentication flow invalidates the SSR transferState + * During an external authentication flow invalidate the SSR transferState * data in the cache. This allows the app to fetch fresh content. * @private */ private externalAuthCheck() { - this.authService.isExternalAuthentication().pipe( + this.sub = this.authService.isExternalAuthentication().pipe( filter((externalAuth: boolean) => externalAuth) ).subscribe(() => { // Clear the transferState data. @@ -154,6 +158,19 @@ export class BrowserInitService extends InitService { } ); + this.closeAuthCheckSubscription(); + } + + /** + * Unsubscribe the external authentication subscription + * when authentication is no longer blocking. + * @private + */ + private closeAuthCheckSubscription() { + firstValueFrom(this.authenticationReady$()).then(() => { + this.sub.unsubscribe(); + } + ) } }