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