@howone/sdk 0.1.24 → 0.1.25

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
@@ -1581,25 +1581,38 @@ var HowOneProvider = ({
1581
1581
  }) => {
1582
1582
  const [user, setUser] = useState4(() => parseUserFromToken(getToken()));
1583
1583
  const [token, setTokenState] = useState4(() => getToken());
1584
+ const [hasCheckedUrlToken, setHasCheckedUrlToken] = useState4(false);
1584
1585
  useEffect4(() => {
1585
1586
  try {
1586
1587
  const params = new URLSearchParams(window.location.search);
1587
- const urlToken = params.get("access_token") || params.get("token");
1588
+ let urlToken = params.get("access_token") || params.get("token");
1589
+ if (!urlToken && window.location.hash) {
1590
+ const hashParams = new URLSearchParams(window.location.hash.slice(1));
1591
+ urlToken = hashParams.get("access_token") || hashParams.get("token");
1592
+ }
1588
1593
  if (urlToken) {
1594
+ console.log("[HowOneProvider] Token captured from URL, storing to localStorage...");
1589
1595
  setToken(urlToken);
1590
1596
  setTokenState(urlToken);
1591
1597
  setUser(parseUserFromToken(urlToken));
1592
1598
  params.delete("access_token");
1593
1599
  params.delete("token");
1600
+ params.delete("project_id");
1594
1601
  const newSearch = params.toString();
1595
- const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "") + window.location.hash;
1602
+ const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
1596
1603
  window.history.replaceState({}, "", newUrl);
1604
+ console.log("[HowOneProvider] Token stored successfully, URL cleaned");
1597
1605
  }
1598
1606
  } catch (e) {
1599
1607
  console.error("[HowOneProvider] Failed to capture token from URL:", e);
1608
+ } finally {
1609
+ setHasCheckedUrlToken(true);
1600
1610
  }
1601
1611
  }, []);
1602
1612
  useEffect4(() => {
1613
+ if (!hasCheckedUrlToken) {
1614
+ return;
1615
+ }
1603
1616
  if (redirectOnUnauthenticated && !token && !user) {
1604
1617
  const currentUrl = new URL(window.location.href);
1605
1618
  if (!currentUrl.pathname.includes("/auth")) {
@@ -1619,7 +1632,7 @@ var HowOneProvider = ({
1619
1632
  }
1620
1633
  }
1621
1634
  }
1622
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId]);
1635
+ }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
1623
1636
  const logout = () => {
1624
1637
  try {
1625
1638
  setToken(null);