@insforge/react 0.2.8 → 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
@@ -1260,6 +1260,7 @@ function SignInForm({
1260
1260
  );
1261
1261
  }
1262
1262
  function SignIn({
1263
+ afterSignInUrl,
1263
1264
  onSuccess,
1264
1265
  onError,
1265
1266
  ...uiProps
@@ -1299,10 +1300,9 @@ function SignIn({
1299
1300
  try {
1300
1301
  setOauthLoading(provider);
1301
1302
  setError("");
1302
- const redirectTo = `${window.location.origin}/auth/callback`;
1303
1303
  await insforge.auth.signInWithOAuth({
1304
1304
  provider,
1305
- redirectTo
1305
+ redirectTo: afterSignInUrl
1306
1306
  });
1307
1307
  } catch (err) {
1308
1308
  const errorMessage = err.message || `${provider} sign in failed`;
@@ -1481,6 +1481,7 @@ function SignUpForm({
1481
1481
  );
1482
1482
  }
1483
1483
  function SignUp({
1484
+ afterSignUpUrl,
1484
1485
  onSuccess,
1485
1486
  onError,
1486
1487
  ...uiProps
@@ -1525,10 +1526,9 @@ function SignUp({
1525
1526
  try {
1526
1527
  setOauthLoading(provider);
1527
1528
  setError("");
1528
- const redirectTo = `${window.location.origin}/auth/callback`;
1529
1529
  await insforge.auth.signInWithOAuth({
1530
1530
  provider,
1531
- redirectTo
1531
+ redirectTo: afterSignUpUrl
1532
1532
  });
1533
1533
  } catch (err) {
1534
1534
  const errorMessage = err.message || `${provider} sign up failed`;
@@ -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" })