@insforge/react 0.2.9 → 0.2.10

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
@@ -1735,18 +1735,19 @@ function SignedOut({ children }) {
1735
1735
  return /* @__PURE__ */ jsx(Fragment, { children });
1736
1736
  }
1737
1737
  function InsforgeCallback({
1738
- redirectTo,
1738
+ redirectTo = "/",
1739
1739
  onSuccess,
1740
1740
  onError,
1741
1741
  loadingComponent,
1742
1742
  onRedirect
1743
1743
  }) {
1744
1744
  const isProcessingRef = useRef(false);
1745
- const { handleAuthCallback } = useInsforge();
1745
+ const { isLoaded, isSignedIn } = useInsforge();
1746
1746
  useEffect(() => {
1747
+ if (!isLoaded) return;
1748
+ if (isProcessingRef.current) return;
1749
+ isProcessingRef.current = true;
1747
1750
  const processCallback = async () => {
1748
- if (isProcessingRef.current) return;
1749
- isProcessingRef.current = true;
1750
1751
  const searchParams = new URLSearchParams(window.location.search);
1751
1752
  const error = searchParams.get("error");
1752
1753
  if (error) {
@@ -1762,26 +1763,8 @@ function InsforgeCallback({
1762
1763
  }
1763
1764
  return;
1764
1765
  }
1765
- const accessToken = searchParams.get("access_token");
1766
- if (!accessToken) {
1767
- const errorMsg = "no_token";
1768
- if (onError) {
1769
- onError(errorMsg);
1770
- } else {
1771
- const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
1772
- if (onRedirect) {
1773
- onRedirect(errorUrl);
1774
- } else {
1775
- window.location.href = errorUrl;
1776
- }
1777
- }
1778
- return;
1779
- }
1780
- const result = await handleAuthCallback({
1781
- accessToken
1782
- });
1783
- if (!result.success) {
1784
- const errorMsg = result.error || "authentication_failed";
1766
+ if (!isSignedIn) {
1767
+ const errorMsg = "authentication_failed";
1785
1768
  if (onError) {
1786
1769
  onError(errorMsg);
1787
1770
  } else {
@@ -1798,17 +1781,14 @@ function InsforgeCallback({
1798
1781
  if (onSuccess) {
1799
1782
  onSuccess();
1800
1783
  }
1801
- const destination = redirectTo || sessionStorage.getItem("auth_destination") || sessionStorage.getItem("oauth_final_destination") || "/";
1802
- sessionStorage.removeItem("auth_destination");
1803
- sessionStorage.removeItem("oauth_final_destination");
1804
1784
  if (onRedirect) {
1805
- onRedirect(destination);
1785
+ onRedirect(redirectTo);
1806
1786
  } else {
1807
- window.location.href = destination;
1787
+ window.location.href = redirectTo;
1808
1788
  }
1809
1789
  };
1810
1790
  processCallback();
1811
- }, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
1791
+ }, [isLoaded, isSignedIn, redirectTo, onSuccess, onError, onRedirect]);
1812
1792
  const defaultLoading = /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
1813
1793
  /* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
1814
1794
  /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })