@@ -26,16 +26,21 @@ import { AuthService } from '../../app/core/auth/auth.service';
2626import { ThemeService } from '../../app/shared/theme-support/theme.service' ;
2727import { StoreAction , StoreActionTypes } from '../../app/store.actions' ;
2828import { coreSelector } from '../../app/core/core.selectors' ;
29- import { find , map } from 'rxjs/operators' ;
29+ import { filter , find , map } from 'rxjs/operators' ;
3030import { isNotEmpty } from '../../app/shared/empty.util' ;
3131import { logStartupMessage } from '../../../startup-message' ;
3232import { MenuService } from '../../app/shared/menu/menu.service' ;
33+ import { RootDataService } from '../../app/core/data/root-data.service' ;
34+ import { firstValueFrom , Subscription } from 'rxjs' ;
3335
3436/**
3537 * Performs client-side initialization.
3638 */
3739@Injectable ( )
3840export class BrowserInitService extends InitService {
41+
42+ sub : Subscription ;
43+
3944 constructor (
4045 protected store : Store < AppState > ,
4146 protected correlationIdService : CorrelationIdService ,
@@ -51,6 +56,7 @@ export class BrowserInitService extends InitService {
5156 protected authService : AuthService ,
5257 protected themeService : ThemeService ,
5358 protected menuService : MenuService ,
59+ private rootDataService : RootDataService
5460 ) {
5561 super (
5662 store ,
@@ -80,6 +86,7 @@ export class BrowserInitService extends InitService {
8086 return async ( ) => {
8187 await this . loadAppState ( ) ;
8288 this . checkAuthenticationToken ( ) ;
89+ this . externalAuthCheck ( ) ;
8390 this . initCorrelationId ( ) ;
8491
8592 this . checkEnvironment ( ) ;
@@ -134,4 +141,35 @@ export class BrowserInitService extends InitService {
134141 protected initGoogleAnalytics ( ) {
135142 this . googleAnalyticsService . addTrackingIdToPage ( ) ;
136143 }
144+
145+ /**
146+ * During an external authentication flow invalidate the SSR transferState
147+ * data in the cache. This allows the app to fetch fresh content.
148+ * @private
149+ */
150+ private externalAuthCheck ( ) {
151+
152+ this . sub = this . authService . isExternalAuthentication ( ) . pipe (
153+ filter ( ( externalAuth : boolean ) => externalAuth )
154+ ) . subscribe ( ( ) => {
155+ // Clear the transferState data.
156+ this . rootDataService . invalidateRootCache ( ) ;
157+ this . authService . setExternalAuthStatus ( false ) ;
158+ }
159+ ) ;
160+
161+ this . closeAuthCheckSubscription ( ) ;
162+ }
163+
164+ /**
165+ * Unsubscribe the external authentication subscription
166+ * when authentication is no longer blocking.
167+ * @private
168+ */
169+ private closeAuthCheckSubscription ( ) {
170+ firstValueFrom ( this . authenticationReady$ ( ) ) . then ( ( ) => {
171+ this . sub . unsubscribe ( ) ;
172+ } ) ;
173+ }
174+
137175}
0 commit comments