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.js CHANGED
@@ -1484,6 +1484,7 @@ var DeviceLogin = ({
1484
1484
  };
1485
1485
  function useProtectedFetch(options = {}) {
1486
1486
  const auth = useAuth();
1487
+ const refreshInProgressRef = react.useRef(false);
1487
1488
  const {
1488
1489
  baseUrl = "",
1489
1490
  onUnauthorized,
@@ -1533,7 +1534,8 @@ function useProtectedFetch(options = {}) {
1533
1534
  });
1534
1535
  if (response.status === 401) {
1535
1536
  onUnauthorized?.();
1536
- if (retryOn401 && auth.user) {
1537
+ if (retryOn401 && auth.user && !refreshInProgressRef.current) {
1538
+ refreshInProgressRef.current = true;
1537
1539
  try {
1538
1540
  await auth.signinSilent();
1539
1541
  const newHeaders = buildHeaders(init?.headers);
@@ -1544,6 +1546,10 @@ function useProtectedFetch(options = {}) {
1544
1546
  return retryResponse;
1545
1547
  } catch (error) {
1546
1548
  return response;
1549
+ } finally {
1550
+ setTimeout(() => {
1551
+ refreshInProgressRef.current = false;
1552
+ }, 1e3);
1547
1553
  }
1548
1554
  }
1549
1555
  }