antaeus.keycloak.react 2.1.1 → 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.mjs CHANGED
@@ -1481,6 +1481,7 @@ var DeviceLogin = ({
1481
1481
  };
1482
1482
  function useProtectedFetch(options = {}) {
1483
1483
  const auth = useAuth();
1484
+ const refreshInProgressRef = useRef(false);
1484
1485
  const {
1485
1486
  baseUrl = "",
1486
1487
  onUnauthorized,
@@ -1530,7 +1531,8 @@ function useProtectedFetch(options = {}) {
1530
1531
  });
1531
1532
  if (response.status === 401) {
1532
1533
  onUnauthorized?.();
1533
- if (retryOn401 && auth.user) {
1534
+ if (retryOn401 && auth.user && !refreshInProgressRef.current) {
1535
+ refreshInProgressRef.current = true;
1534
1536
  try {
1535
1537
  await auth.signinSilent();
1536
1538
  const newHeaders = buildHeaders(init?.headers);
@@ -1541,6 +1543,10 @@ function useProtectedFetch(options = {}) {
1541
1543
  return retryResponse;
1542
1544
  } catch (error) {
1543
1545
  return response;
1546
+ } finally {
1547
+ setTimeout(() => {
1548
+ refreshInProgressRef.current = false;
1549
+ }, 1e3);
1544
1550
  }
1545
1551
  }
1546
1552
  }