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.mjs
CHANGED
|
@@ -201,14 +201,14 @@ function useTokenLifecycle(options) {
|
|
|
201
201
|
log("Refresh already in progress, skipping");
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
|
-
|
|
205
|
-
log("Refresh token exceeded max lifetime, cannot refresh");
|
|
206
|
-
setIsRefreshTokenExpired(true);
|
|
207
|
-
onRefreshTokenExpired?.();
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
204
|
+
setIsRefreshing(true);
|
|
210
205
|
try {
|
|
211
|
-
|
|
206
|
+
if (checkRefreshTokenLifetime()) {
|
|
207
|
+
log("Refresh token exceeded max lifetime, cannot refresh");
|
|
208
|
+
setIsRefreshTokenExpired(true);
|
|
209
|
+
onRefreshTokenExpired?.();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
212
|
onRefreshStart?.();
|
|
213
213
|
log("Starting token refresh");
|
|
214
214
|
await auth.signinSilent();
|
|
@@ -1401,8 +1401,17 @@ var DeviceLogin = ({
|
|
|
1401
1401
|
});
|
|
1402
1402
|
if (userManagerRef.current) {
|
|
1403
1403
|
await userManagerRef.current.storeUser(user);
|
|
1404
|
+
const events = userManagerRef.current.events;
|
|
1405
|
+
if (events && events._userLoaded) {
|
|
1406
|
+
events._userLoaded.raise(user);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (onSuccess) {
|
|
1410
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1411
|
+
onSuccess(user);
|
|
1412
|
+
} else {
|
|
1413
|
+
window.location.reload();
|
|
1404
1414
|
}
|
|
1405
|
-
onSuccess?.(user);
|
|
1406
1415
|
}
|
|
1407
1416
|
} catch (err) {
|
|
1408
1417
|
if (!err.message.includes("authorization_pending")) {
|
|
@@ -1472,6 +1481,7 @@ var DeviceLogin = ({
|
|
|
1472
1481
|
};
|
|
1473
1482
|
function useProtectedFetch(options = {}) {
|
|
1474
1483
|
const auth = useAuth();
|
|
1484
|
+
const refreshInProgressRef = useRef(false);
|
|
1475
1485
|
const {
|
|
1476
1486
|
baseUrl = "",
|
|
1477
1487
|
onUnauthorized,
|
|
@@ -1521,7 +1531,8 @@ function useProtectedFetch(options = {}) {
|
|
|
1521
1531
|
});
|
|
1522
1532
|
if (response.status === 401) {
|
|
1523
1533
|
onUnauthorized?.();
|
|
1524
|
-
if (retryOn401 && auth.user) {
|
|
1534
|
+
if (retryOn401 && auth.user && !refreshInProgressRef.current) {
|
|
1535
|
+
refreshInProgressRef.current = true;
|
|
1525
1536
|
try {
|
|
1526
1537
|
await auth.signinSilent();
|
|
1527
1538
|
const newHeaders = buildHeaders(init?.headers);
|
|
@@ -1532,6 +1543,10 @@ function useProtectedFetch(options = {}) {
|
|
|
1532
1543
|
return retryResponse;
|
|
1533
1544
|
} catch (error) {
|
|
1534
1545
|
return response;
|
|
1546
|
+
} finally {
|
|
1547
|
+
setTimeout(() => {
|
|
1548
|
+
refreshInProgressRef.current = false;
|
|
1549
|
+
}, 1e3);
|
|
1535
1550
|
}
|
|
1536
1551
|
}
|
|
1537
1552
|
}
|