@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.js CHANGED
@@ -1641,25 +1641,38 @@ var HowOneProvider = ({
1641
1641
  }) => {
1642
1642
  const [user, setUser] = (0, import_react5.useState)(() => parseUserFromToken(getToken()));
1643
1643
  const [token, setTokenState] = (0, import_react5.useState)(() => getToken());
1644
+ const [hasCheckedUrlToken, setHasCheckedUrlToken] = (0, import_react5.useState)(false);
1644
1645
  (0, import_react5.useEffect)(() => {
1645
1646
  try {
1646
1647
  const params = new URLSearchParams(window.location.search);
1647
- const urlToken = params.get("access_token") || params.get("token");
1648
+ let urlToken = params.get("access_token") || params.get("token");
1649
+ if (!urlToken && window.location.hash) {
1650
+ const hashParams = new URLSearchParams(window.location.hash.slice(1));
1651
+ urlToken = hashParams.get("access_token") || hashParams.get("token");
1652
+ }
1648
1653
  if (urlToken) {
1654
+ console.log("[HowOneProvider] Token captured from URL, storing to localStorage...");
1649
1655
  setToken(urlToken);
1650
1656
  setTokenState(urlToken);
1651
1657
  setUser(parseUserFromToken(urlToken));
1652
1658
  params.delete("access_token");
1653
1659
  params.delete("token");
1660
+ params.delete("project_id");
1654
1661
  const newSearch = params.toString();
1655
- const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "") + window.location.hash;
1662
+ const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
1656
1663
  window.history.replaceState({}, "", newUrl);
1664
+ console.log("[HowOneProvider] Token stored successfully, URL cleaned");
1657
1665
  }
1658
1666
  } catch (e) {
1659
1667
  console.error("[HowOneProvider] Failed to capture token from URL:", e);
1668
+ } finally {
1669
+ setHasCheckedUrlToken(true);
1660
1670
  }
1661
1671
  }, []);
1662
1672
  (0, import_react5.useEffect)(() => {
1673
+ if (!hasCheckedUrlToken) {
1674
+ return;
1675
+ }
1663
1676
  if (redirectOnUnauthenticated && !token && !user) {
1664
1677
  const currentUrl = new URL(window.location.href);
1665
1678
  if (!currentUrl.pathname.includes("/auth")) {
@@ -1679,7 +1692,7 @@ var HowOneProvider = ({
1679
1692
  }
1680
1693
  }
1681
1694
  }
1682
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId]);
1695
+ }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
1683
1696
  const logout = () => {
1684
1697
  try {
1685
1698
  setToken(null);