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