@codex-ts/core-lib 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -322,8 +322,15 @@ class KeycloakAuthGuard {
|
|
|
322
322
|
keycloakService = inject(KeycloakService);
|
|
323
323
|
config = inject(KEYCLOAK_CONFIG);
|
|
324
324
|
router = inject(Router);
|
|
325
|
+
platformId = inject(PLATFORM_ID);
|
|
325
326
|
canActivate(route, state) {
|
|
326
327
|
return new Observable(subscriber => {
|
|
328
|
+
// In SSR, default to not authenticated
|
|
329
|
+
if (!isPlatformBrowser(this.platformId)) {
|
|
330
|
+
subscriber.next(false);
|
|
331
|
+
subscriber.complete();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
327
334
|
const authenticated = this.keycloakService.isAuthenticated$();
|
|
328
335
|
subscriber.next(this.processAuthentication(authenticated, route, state));
|
|
329
336
|
subscriber.complete();
|
|
@@ -331,7 +338,10 @@ class KeycloakAuthGuard {
|
|
|
331
338
|
}
|
|
332
339
|
processAuthentication(authenticated, route, state) {
|
|
333
340
|
if (!authenticated) {
|
|
334
|
-
|
|
341
|
+
const redirectUri = isPlatformBrowser(this.platformId)
|
|
342
|
+
? window.location.origin + state.url
|
|
343
|
+
: state.url;
|
|
344
|
+
this.keycloakService.login({ redirectUri });
|
|
335
345
|
return false;
|
|
336
346
|
}
|
|
337
347
|
// Check for route-specific roles first, then fallback to default roles
|