@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.
@@ -154,15 +154,20 @@ interface InsforgeCallbackProps {
154
154
  onRedirect?: (url: string) => void;
155
155
  }
156
156
  /**
157
- * InsforgeCallback - Handles OAuth and email/password authentication callbacks
157
+ * InsforgeCallback - Handles OAuth authentication callbacks
158
158
  *
159
159
  * Place this component on your `/auth/callback` page.
160
160
  *
161
+ * How it works:
162
+ * 1. SDK automatically detects OAuth callback parameters and saves to localStorage
163
+ * 2. Provider validates the session from localStorage
164
+ * 3. This component waits for validation and handles redirect
165
+ *
161
166
  * @example
162
167
  * ```tsx
163
168
  * // Minimal usage
164
169
  * export default function CallbackPage() {
165
- * return <InsforgeCallback />;
170
+ * return <InsforgeCallback redirectTo="/dashboard" />;
166
171
  * }
167
172
  * ```
168
173
  *
@@ -154,15 +154,20 @@ interface InsforgeCallbackProps {
154
154
  onRedirect?: (url: string) => void;
155
155
  }
156
156
  /**
157
- * InsforgeCallback - Handles OAuth and email/password authentication callbacks
157
+ * InsforgeCallback - Handles OAuth authentication callbacks
158
158
  *
159
159
  * Place this component on your `/auth/callback` page.
160
160
  *
161
+ * How it works:
162
+ * 1. SDK automatically detects OAuth callback parameters and saves to localStorage
163
+ * 2. Provider validates the session from localStorage
164
+ * 3. This component waits for validation and handles redirect
165
+ *
161
166
  * @example
162
167
  * ```tsx
163
168
  * // Minimal usage
164
169
  * export default function CallbackPage() {
165
- * return <InsforgeCallback />;
170
+ * return <InsforgeCallback redirectTo="/dashboard" />;
166
171
  * }
167
172
  * ```
168
173
  *
@@ -1386,18 +1386,19 @@ function SignedOut({ children }) {
1386
1386
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1387
1387
  }
1388
1388
  function InsforgeCallback({
1389
- redirectTo,
1389
+ redirectTo = "/",
1390
1390
  onSuccess,
1391
1391
  onError,
1392
1392
  loadingComponent,
1393
1393
  onRedirect
1394
1394
  }) {
1395
1395
  const isProcessingRef = react.useRef(false);
1396
- const { handleAuthCallback } = useInsforge();
1396
+ const { isLoaded, isSignedIn } = useInsforge();
1397
1397
  react.useEffect(() => {
1398
+ if (!isLoaded) return;
1399
+ if (isProcessingRef.current) return;
1400
+ isProcessingRef.current = true;
1398
1401
  const processCallback = async () => {
1399
- if (isProcessingRef.current) return;
1400
- isProcessingRef.current = true;
1401
1402
  const searchParams = new URLSearchParams(window.location.search);
1402
1403
  const error = searchParams.get("error");
1403
1404
  if (error) {
@@ -1413,26 +1414,8 @@ function InsforgeCallback({
1413
1414
  }
1414
1415
  return;
1415
1416
  }
1416
- const accessToken = searchParams.get("access_token");
1417
- if (!accessToken) {
1418
- const errorMsg = "no_token";
1419
- if (onError) {
1420
- onError(errorMsg);
1421
- } else {
1422
- const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
1423
- if (onRedirect) {
1424
- onRedirect(errorUrl);
1425
- } else {
1426
- window.location.href = errorUrl;
1427
- }
1428
- }
1429
- return;
1430
- }
1431
- const result = await handleAuthCallback({
1432
- accessToken
1433
- });
1434
- if (!result.success) {
1435
- const errorMsg = result.error || "authentication_failed";
1417
+ if (!isSignedIn) {
1418
+ const errorMsg = "authentication_failed";
1436
1419
  if (onError) {
1437
1420
  onError(errorMsg);
1438
1421
  } else {
@@ -1449,17 +1432,14 @@ function InsforgeCallback({
1449
1432
  if (onSuccess) {
1450
1433
  onSuccess();
1451
1434
  }
1452
- const destination = redirectTo || sessionStorage.getItem("auth_destination") || sessionStorage.getItem("oauth_final_destination") || "/";
1453
- sessionStorage.removeItem("auth_destination");
1454
- sessionStorage.removeItem("oauth_final_destination");
1455
1435
  if (onRedirect) {
1456
- onRedirect(destination);
1436
+ onRedirect(redirectTo);
1457
1437
  } else {
1458
- window.location.href = destination;
1438
+ window.location.href = redirectTo;
1459
1439
  }
1460
1440
  };
1461
1441
  processCallback();
1462
- }, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
1442
+ }, [isLoaded, isSignedIn, redirectTo, onSuccess, onError, onRedirect]);
1463
1443
  const defaultLoading = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
1464
1444
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
1465
1445
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })