antaeus.keycloak.react 2.1.0 → 2.1.2
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 +24 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -204,14 +204,14 @@ function useTokenLifecycle(options) {
|
|
|
204
204
|
log("Refresh already in progress, skipping");
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
log("Refresh token exceeded max lifetime, cannot refresh");
|
|
209
|
-
setIsRefreshTokenExpired(true);
|
|
210
|
-
onRefreshTokenExpired?.();
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
207
|
+
setIsRefreshing(true);
|
|
213
208
|
try {
|
|
214
|
-
|
|
209
|
+
if (checkRefreshTokenLifetime()) {
|
|
210
|
+
log("Refresh token exceeded max lifetime, cannot refresh");
|
|
211
|
+
setIsRefreshTokenExpired(true);
|
|
212
|
+
onRefreshTokenExpired?.();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
215
|
onRefreshStart?.();
|
|
216
216
|
log("Starting token refresh");
|
|
217
217
|
await auth.signinSilent();
|
|
@@ -1404,8 +1404,17 @@ var DeviceLogin = ({
|
|
|
1404
1404
|
});
|
|
1405
1405
|
if (userManagerRef.current) {
|
|
1406
1406
|
await userManagerRef.current.storeUser(user);
|
|
1407
|
+
const events = userManagerRef.current.events;
|
|
1408
|
+
if (events && events._userLoaded) {
|
|
1409
|
+
events._userLoaded.raise(user);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (onSuccess) {
|
|
1413
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1414
|
+
onSuccess(user);
|
|
1415
|
+
} else {
|
|
1416
|
+
window.location.reload();
|
|
1407
1417
|
}
|
|
1408
|
-
onSuccess?.(user);
|
|
1409
1418
|
}
|
|
1410
1419
|
} catch (err) {
|
|
1411
1420
|
if (!err.message.includes("authorization_pending")) {
|
|
@@ -1475,6 +1484,7 @@ var DeviceLogin = ({
|
|
|
1475
1484
|
};
|
|
1476
1485
|
function useProtectedFetch(options = {}) {
|
|
1477
1486
|
const auth = useAuth();
|
|
1487
|
+
const refreshInProgressRef = react.useRef(false);
|
|
1478
1488
|
const {
|
|
1479
1489
|
baseUrl = "",
|
|
1480
1490
|
onUnauthorized,
|
|
@@ -1524,7 +1534,8 @@ function useProtectedFetch(options = {}) {
|
|
|
1524
1534
|
});
|
|
1525
1535
|
if (response.status === 401) {
|
|
1526
1536
|
onUnauthorized?.();
|
|
1527
|
-
if (retryOn401 && auth.user) {
|
|
1537
|
+
if (retryOn401 && auth.user && !refreshInProgressRef.current) {
|
|
1538
|
+
refreshInProgressRef.current = true;
|
|
1528
1539
|
try {
|
|
1529
1540
|
await auth.signinSilent();
|
|
1530
1541
|
const newHeaders = buildHeaders(init?.headers);
|
|
@@ -1535,6 +1546,10 @@ function useProtectedFetch(options = {}) {
|
|
|
1535
1546
|
return retryResponse;
|
|
1536
1547
|
} catch (error) {
|
|
1537
1548
|
return response;
|
|
1549
|
+
} finally {
|
|
1550
|
+
setTimeout(() => {
|
|
1551
|
+
refreshInProgressRef.current = false;
|
|
1552
|
+
}, 1e3);
|
|
1538
1553
|
}
|
|
1539
1554
|
}
|
|
1540
1555
|
}
|