antaeus.keycloak.react 2.2.2 → 2.2.3

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.
package/dist/index.js CHANGED
@@ -837,6 +837,15 @@ function mergeWithPreset(preset, customConfig) {
837
837
  }
838
838
  };
839
839
  }
840
+ var StorageConfigContext = react.createContext({
841
+ storageType: "session",
842
+ storage: typeof window !== "undefined" ? window.sessionStorage : {}
843
+ });
844
+ var StorageConfigProvider = ({ storageType, children }) => {
845
+ const storage = storageType === "local" ? window.localStorage : window.sessionStorage;
846
+ return /* @__PURE__ */ jsxRuntime.jsx(StorageConfigContext.Provider, { value: { storageType, storage }, children });
847
+ };
848
+ var useStorageConfig = () => react.useContext(StorageConfigContext);
840
849
  function isZeroConfig(props) {
841
850
  return "authority" in props && "clientId" in props;
842
851
  }
@@ -882,6 +891,7 @@ var KeycloakProvider = (props) => {
882
891
  log("warn", "User removed from storage - token validation likely failed");
883
892
  }, [log]);
884
893
  const showSessionMonitor = config.features?.sessionMonitor !== false;
894
+ const storageType = config.advanced?.storageType || "session";
885
895
  return /* @__PURE__ */ jsxRuntime.jsx(
886
896
  reactOidcContext.AuthProvider,
887
897
  {
@@ -889,10 +899,10 @@ var KeycloakProvider = (props) => {
889
899
  onSigninCallback,
890
900
  onSignoutCallback,
891
901
  onRemoveUser,
892
- children: /* @__PURE__ */ jsxRuntime.jsxs(TokenLifecycleManager, { config, debug, children: [
902
+ children: /* @__PURE__ */ jsxRuntime.jsx(StorageConfigProvider, { storageType, children: /* @__PURE__ */ jsxRuntime.jsxs(TokenLifecycleManager, { config, debug, children: [
893
903
  showSessionMonitor && /* @__PURE__ */ jsxRuntime.jsx(SessionMonitor, {}),
894
904
  children
895
- ] })
905
+ ] }) })
896
906
  }
897
907
  );
898
908
  };
@@ -1349,6 +1359,7 @@ var DeviceLogin = ({
1349
1359
  style
1350
1360
  }) => {
1351
1361
  const auth = useAuth();
1362
+ const { storage, storageType } = useStorageConfig();
1352
1363
  const [deviceData, setDeviceData] = react.useState(null);
1353
1364
  const [error, setError] = react.useState(null);
1354
1365
  const [loading, setLoading] = react.useState(true);
@@ -1415,10 +1426,10 @@ var DeviceLogin = ({
1415
1426
  });
1416
1427
  const storageKey = `oidc.user:${auth.settings.authority}:${auth.settings.client_id}`;
1417
1428
  const userJson = user.toStorageString();
1418
- const storage = auth.settings.userStore?.store || window.sessionStorage;
1419
1429
  console.log("[DeviceLogin] Storing user in storage...", {
1420
1430
  storageKey,
1421
- storageType: storage === window.localStorage ? "localStorage" : "sessionStorage"
1431
+ storageType,
1432
+ storage: storageType === "local" ? "localStorage" : "sessionStorage"
1422
1433
  });
1423
1434
  storage.setItem(storageKey, userJson);
1424
1435
  const stored = storage.getItem(storageKey);
@@ -1426,7 +1437,7 @@ var DeviceLogin = ({
1426
1437
  console.error("[DeviceLogin] Failed to store user in storage!");
1427
1438
  throw new Error("Failed to store user session. Please try again.");
1428
1439
  }
1429
- console.log("[DeviceLogin] User stored successfully in", storage === window.localStorage ? "localStorage" : "sessionStorage");
1440
+ console.log("[DeviceLogin] User stored successfully in", storageType === "local" ? "localStorage" : "sessionStorage");
1430
1441
  if (onSuccess) {
1431
1442
  await new Promise((resolve) => setTimeout(resolve, 100));
1432
1443
  onSuccess(user);