@erikey/react 0.3.1 → 0.3.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.mjs CHANGED
@@ -1662,6 +1662,10 @@ function clearToken(projectId) {
1662
1662
  function createAuthClient2(config) {
1663
1663
  const { projectId, baseUrl = "https://auth.erikey.com" } = config;
1664
1664
  const useBearerAuth = shouldUseBearerAuth(baseUrl);
1665
+ const sessionListeners = /* @__PURE__ */ new Set();
1666
+ const notifySessionChange = () => {
1667
+ sessionListeners.forEach((listener) => listener());
1668
+ };
1665
1669
  const fetchOptions = {
1666
1670
  // Always send project ID header for multi-tenant routing
1667
1671
  headers: {
@@ -1720,6 +1724,7 @@ function createAuthClient2(config) {
1720
1724
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
1721
1725
  };
1722
1726
  storeToken(projectId, session);
1727
+ notifySessionChange();
1723
1728
  }
1724
1729
  return result;
1725
1730
  };
@@ -1743,6 +1748,7 @@ function createAuthClient2(config) {
1743
1748
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
1744
1749
  };
1745
1750
  storeToken(projectId, session);
1751
+ notifySessionChange();
1746
1752
  }
1747
1753
  return result;
1748
1754
  };
@@ -1754,7 +1760,9 @@ function createAuthClient2(config) {
1754
1760
  if (prop === "signOut") {
1755
1761
  return async (...args) => {
1756
1762
  clearToken(projectId);
1757
- return client.signOut(...args);
1763
+ const result = await client.signOut(...args);
1764
+ notifySessionChange();
1765
+ return result;
1758
1766
  };
1759
1767
  }
1760
1768
  if (prop === "useSession") {
@@ -1782,6 +1790,12 @@ function createAuthClient2(config) {
1782
1790
  useEffect(() => {
1783
1791
  refetch();
1784
1792
  }, [refetch]);
1793
+ useEffect(() => {
1794
+ sessionListeners.add(refetch);
1795
+ return () => {
1796
+ sessionListeners.delete(refetch);
1797
+ };
1798
+ }, [refetch]);
1785
1799
  return { data, isPending, error, refetch };
1786
1800
  };
1787
1801
  }