antaeus.keycloak.react 2.1.2 → 2.1.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 CHANGED
@@ -1485,6 +1485,7 @@ var DeviceLogin = ({
1485
1485
  function useProtectedFetch(options = {}) {
1486
1486
  const auth = useAuth();
1487
1487
  const refreshInProgressRef = react.useRef(false);
1488
+ const { user, isLoading, signinSilent } = auth;
1488
1489
  const {
1489
1490
  baseUrl = "",
1490
1491
  onUnauthorized,
@@ -1503,11 +1504,11 @@ function useProtectedFetch(options = {}) {
1503
1504
  [baseUrl]
1504
1505
  );
1505
1506
  const getAuthHeader = () => {
1506
- if (!auth.user?.access_token) {
1507
+ if (!user?.access_token) {
1507
1508
  return {};
1508
1509
  }
1509
1510
  return {
1510
- Authorization: `Bearer ${auth.user.access_token}`
1511
+ Authorization: `Bearer ${user.access_token}`
1511
1512
  };
1512
1513
  };
1513
1514
  const buildHeaders = react.useCallback(
@@ -1534,10 +1535,10 @@ function useProtectedFetch(options = {}) {
1534
1535
  });
1535
1536
  if (response.status === 401) {
1536
1537
  onUnauthorized?.();
1537
- if (retryOn401 && auth.user && !refreshInProgressRef.current) {
1538
+ if (retryOn401 && user && !refreshInProgressRef.current) {
1538
1539
  refreshInProgressRef.current = true;
1539
1540
  try {
1540
- await auth.signinSilent();
1541
+ await signinSilent();
1541
1542
  const newHeaders = buildHeaders(init?.headers);
1542
1543
  const retryResponse = await fetch(fullUrl, {
1543
1544
  ...init,
@@ -1555,7 +1556,7 @@ function useProtectedFetch(options = {}) {
1555
1556
  }
1556
1557
  return response;
1557
1558
  },
1558
- [buildUrl, buildHeaders, onUnauthorized, retryOn401, auth]
1559
+ [buildUrl, buildHeaders, onUnauthorized, retryOn401, user, signinSilent]
1559
1560
  );
1560
1561
  const fetchJson = react.useCallback(
1561
1562
  async (url, init) => {
@@ -1574,7 +1575,7 @@ function useProtectedFetch(options = {}) {
1574
1575
  return {
1575
1576
  fetchJson,
1576
1577
  fetch: protectedFetch,
1577
- isLoading: auth.isLoading
1578
+ isLoading
1578
1579
  };
1579
1580
  }
1580
1581