|
1 | | -import { Injectable, NgZone } from '@angular/core'; |
| 1 | +import { Inject, Injectable, NgZone, PLATFORM_ID } from '@angular/core'; |
| 2 | +import { isPlatformBrowser } from '@angular/common'; |
2 | 3 |
|
3 | 4 | import { |
4 | 5 | asyncScheduler, |
@@ -100,7 +101,11 @@ export class AuthEffects { |
100 | 101 | map((redirectUrl: string) => [action, redirectUrl]) |
101 | 102 | )), |
102 | 103 | map(([action, redirectUrl]: [AuthenticatedSuccessAction, string]) => { |
103 | | - if (hasValue(redirectUrl)) { |
| 104 | + // Perform the redirect only in the browser: the server cannot clear the redirect cookie |
| 105 | + // (ServerCookieService.set/remove are no-ops), so a hard redirect during SSR would repeat |
| 106 | + // on every request and create a redirect loop. |
| 107 | + // The browser re-runs this effect after hydration and performs the redirect itself. |
| 108 | + if (hasValue(redirectUrl) && isPlatformBrowser(this.platformId)) { |
104 | 109 | return new RedirectAfterLoginSuccessAction(redirectUrl); |
105 | 110 | } else { |
106 | 111 | return new RetrieveAuthenticatedEpersonAction(action.payload.userHref); |
@@ -287,6 +292,7 @@ export class AuthEffects { |
287 | 292 | private zone: NgZone, |
288 | 293 | private authorizationsService: AuthorizationDataService, |
289 | 294 | private authService: AuthService, |
290 | | - private store: Store<AppState>) { |
| 295 | + private store: Store<AppState>, |
| 296 | + @Inject(PLATFORM_ID) private platformId: any) { |
291 | 297 | } |
292 | 298 | } |
0 commit comments