;
storageKey?: string;
+ /** Defaults to Chakra Spinner when is present; otherwise legacy text. Explicit null disables it. */
loading?: ReactNode;
errorFallback?: ReactNode;
enabled?: boolean;
diff --git a/src/permission/index.jsx b/src/permission/index.jsx
index 50fae3e..1ed93d2 100644
--- a/src/permission/index.jsx
+++ b/src/permission/index.jsx
@@ -1,8 +1,8 @@
"use client";
-import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { defineFeature } from "../internal/feature-registry.jsx";
-import { useKeycloakOptional } from "../internal/provider-runtime.jsx";
+import { ChakraLoadingContext, useKeycloakOptional } from "../internal/provider-runtime.jsx";
// The shared context is React-only and is also consumed by existing uikit/layout.
import { PermissionContext, usePermission } from "../core/runtime.jsx";
@@ -47,11 +47,15 @@ function PermissionLayer({
user = null,
getToken,
storageKey,
- loading = Loading permissions...
,
+ loading,
errorFallback = Error loading permissions
,
enabled = true,
}) {
if (!clientId) throw new Error(" requires clientId.");
+ const chakraLoading = useContext(ChakraLoadingContext);
+ const loadingContent = loading !== undefined
+ ? loading
+ : (chakraLoading ?? Loading permissions...
);
const keycloak = useKeycloakOptional();
// Never reuse one user's cached permissions for another authenticated user.
const identity = keycloak?.instance?.tokenParsed?.sub ?? user?.id ?? "anonymous";
@@ -121,7 +125,7 @@ function PermissionLayer({
refresh, clear,
}), [user, permissions, can, cannot, current.isLoading, current.error, refresh, clear]);
- if (current.isLoading && !permissions) return loading;
+ if (current.isLoading && !permissions) return loadingContent;
if (current.error && !permissions) return errorFallback;
return {children};
}