antaeus.keycloak.react 2.2.1 → 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 +32 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,12 +1359,12 @@ 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);
|
|
1355
1366
|
const [timeRemaining, setTimeRemaining] = react.useState(null);
|
|
1356
1367
|
const pollTimerRef = react.useRef(null);
|
|
1357
|
-
const userManagerRef = react.useRef(null);
|
|
1358
1368
|
react.useEffect(() => {
|
|
1359
1369
|
const initDeviceFlow = async () => {
|
|
1360
1370
|
setLoading(true);
|
|
@@ -1389,16 +1399,6 @@ var DeviceLogin = ({
|
|
|
1389
1399
|
}, [deviceData, timeRemaining]);
|
|
1390
1400
|
react.useEffect(() => {
|
|
1391
1401
|
if (!deviceData) return;
|
|
1392
|
-
userManagerRef.current = auth.userManager;
|
|
1393
|
-
if (userManagerRef.current) {
|
|
1394
|
-
const settings = userManagerRef.current.settings;
|
|
1395
|
-
console.log("[DeviceLogin] UserManager storage configured:", {
|
|
1396
|
-
hasUserStore: !!settings.userStore,
|
|
1397
|
-
storeType: settings.userStore ? "configured" : "default"
|
|
1398
|
-
});
|
|
1399
|
-
} else {
|
|
1400
|
-
console.error("[DeviceLogin] UserManager is not available in auth context");
|
|
1401
|
-
}
|
|
1402
1402
|
const poll = async () => {
|
|
1403
1403
|
try {
|
|
1404
1404
|
const tokenResponse = await pollForToken(apiBaseUrl, deviceData.device_code);
|
|
@@ -1418,32 +1418,26 @@ var DeviceLogin = ({
|
|
|
1418
1418
|
session_state: null
|
|
1419
1419
|
// Device flow doesn't have session_state
|
|
1420
1420
|
});
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
if (events && events._userLoaded) {
|
|
1440
|
-
events._userLoaded.raise(user);
|
|
1441
|
-
console.log("[DeviceLogin] Triggered user loaded event");
|
|
1442
|
-
}
|
|
1443
|
-
} else {
|
|
1444
|
-
console.error("[DeviceLogin] UserManager not available, cannot store user");
|
|
1445
|
-
throw new Error("UserManager not available. Cannot complete login.");
|
|
1421
|
+
console.log("[DeviceLogin] Device flow authentication successful", {
|
|
1422
|
+
hasAccessToken: !!user.access_token,
|
|
1423
|
+
hasRefreshToken: !!user.refresh_token,
|
|
1424
|
+
expiresAt: user.expires_at,
|
|
1425
|
+
profile: userInfo.preferred_username
|
|
1426
|
+
});
|
|
1427
|
+
const storageKey = `oidc.user:${auth.settings.authority}:${auth.settings.client_id}`;
|
|
1428
|
+
const userJson = user.toStorageString();
|
|
1429
|
+
console.log("[DeviceLogin] Storing user in storage...", {
|
|
1430
|
+
storageKey,
|
|
1431
|
+
storageType,
|
|
1432
|
+
storage: storageType === "local" ? "localStorage" : "sessionStorage"
|
|
1433
|
+
});
|
|
1434
|
+
storage.setItem(storageKey, userJson);
|
|
1435
|
+
const stored = storage.getItem(storageKey);
|
|
1436
|
+
if (!stored) {
|
|
1437
|
+
console.error("[DeviceLogin] Failed to store user in storage!");
|
|
1438
|
+
throw new Error("Failed to store user session. Please try again.");
|
|
1446
1439
|
}
|
|
1440
|
+
console.log("[DeviceLogin] User stored successfully in", storageType === "local" ? "localStorage" : "sessionStorage");
|
|
1447
1441
|
if (onSuccess) {
|
|
1448
1442
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1449
1443
|
onSuccess(user);
|