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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useRef, useCallback, useEffect, useMemo } from 'react';
1
+ import { createContext, useState, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
2
2
  import { useAuth as useAuth$1, AuthProvider } from 'react-oidc-context';
3
3
  import { WebStorageStateStore, User } from 'oidc-client-ts';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -834,6 +834,15 @@ function mergeWithPreset(preset, customConfig) {
834
834
  }
835
835
  };
836
836
  }
837
+ var StorageConfigContext = createContext({
838
+ storageType: "session",
839
+ storage: typeof window !== "undefined" ? window.sessionStorage : {}
840
+ });
841
+ var StorageConfigProvider = ({ storageType, children }) => {
842
+ const storage = storageType === "local" ? window.localStorage : window.sessionStorage;
843
+ return /* @__PURE__ */ jsx(StorageConfigContext.Provider, { value: { storageType, storage }, children });
844
+ };
845
+ var useStorageConfig = () => useContext(StorageConfigContext);
837
846
  function isZeroConfig(props) {
838
847
  return "authority" in props && "clientId" in props;
839
848
  }
@@ -879,6 +888,7 @@ var KeycloakProvider = (props) => {
879
888
  log("warn", "User removed from storage - token validation likely failed");
880
889
  }, [log]);
881
890
  const showSessionMonitor = config.features?.sessionMonitor !== false;
891
+ const storageType = config.advanced?.storageType || "session";
882
892
  return /* @__PURE__ */ jsx(
883
893
  AuthProvider,
884
894
  {
@@ -886,10 +896,10 @@ var KeycloakProvider = (props) => {
886
896
  onSigninCallback,
887
897
  onSignoutCallback,
888
898
  onRemoveUser,
889
- children: /* @__PURE__ */ jsxs(TokenLifecycleManager, { config, debug, children: [
899
+ children: /* @__PURE__ */ jsx(StorageConfigProvider, { storageType, children: /* @__PURE__ */ jsxs(TokenLifecycleManager, { config, debug, children: [
890
900
  showSessionMonitor && /* @__PURE__ */ jsx(SessionMonitor, {}),
891
901
  children
892
- ] })
902
+ ] }) })
893
903
  }
894
904
  );
895
905
  };
@@ -1346,6 +1356,7 @@ var DeviceLogin = ({
1346
1356
  style
1347
1357
  }) => {
1348
1358
  const auth = useAuth();
1359
+ const { storage, storageType } = useStorageConfig();
1349
1360
  const [deviceData, setDeviceData] = useState(null);
1350
1361
  const [error, setError] = useState(null);
1351
1362
  const [loading, setLoading] = useState(true);
@@ -1412,10 +1423,10 @@ var DeviceLogin = ({
1412
1423
  });
1413
1424
  const storageKey = `oidc.user:${auth.settings.authority}:${auth.settings.client_id}`;
1414
1425
  const userJson = user.toStorageString();
1415
- const storage = auth.settings.userStore?.store || window.sessionStorage;
1416
1426
  console.log("[DeviceLogin] Storing user in storage...", {
1417
1427
  storageKey,
1418
- storageType: storage === window.localStorage ? "localStorage" : "sessionStorage"
1428
+ storageType,
1429
+ storage: storageType === "local" ? "localStorage" : "sessionStorage"
1419
1430
  });
1420
1431
  storage.setItem(storageKey, userJson);
1421
1432
  const stored = storage.getItem(storageKey);
@@ -1423,7 +1434,7 @@ var DeviceLogin = ({
1423
1434
  console.error("[DeviceLogin] Failed to store user in storage!");
1424
1435
  throw new Error("Failed to store user session. Please try again.");
1425
1436
  }
1426
- console.log("[DeviceLogin] User stored successfully in", storage === window.localStorage ? "localStorage" : "sessionStorage");
1437
+ console.log("[DeviceLogin] User stored successfully in", storageType === "local" ? "localStorage" : "sessionStorage");
1427
1438
  if (onSuccess) {
1428
1439
  await new Promise((resolve) => setTimeout(resolve, 100));
1429
1440
  onSuccess(user);