@insforge/react 0.2.4 → 0.2.6

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.
@@ -21,7 +21,7 @@ import '@insforge/shared-schemas';
21
21
  * />
22
22
  * ```
23
23
  */
24
- declare function SignIn({ afterSignInUrl, onSuccess, onError, onRedirect, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
24
+ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
25
25
 
26
26
  /**
27
27
  * Pre-built sign-up component with full authentication logic.
@@ -38,7 +38,7 @@ declare function SignIn({ afterSignInUrl, onSuccess, onError, onRedirect, ...uiP
38
38
  * />
39
39
  * ```
40
40
  */
41
- declare function SignUp({ afterSignUpUrl, onSuccess, onError, onRedirect, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
41
+ declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
43
  /**
44
44
  * User profile button with dropdown menu and sign-out functionality.
@@ -21,7 +21,7 @@ import '@insforge/shared-schemas';
21
21
  * />
22
22
  * ```
23
23
  */
24
- declare function SignIn({ afterSignInUrl, onSuccess, onError, onRedirect, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
24
+ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
25
25
 
26
26
  /**
27
27
  * Pre-built sign-up component with full authentication logic.
@@ -38,7 +38,7 @@ declare function SignIn({ afterSignInUrl, onSuccess, onError, onRedirect, ...uiP
38
38
  * />
39
39
  * ```
40
40
  */
41
- declare function SignUp({ afterSignUpUrl, onSuccess, onError, onRedirect, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
41
+ declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
43
  /**
44
44
  * User profile button with dropdown menu and sign-out functionality.
@@ -911,10 +911,8 @@ function SignInForm({
911
911
  );
912
912
  }
913
913
  function SignIn({
914
- afterSignInUrl = "/",
915
914
  onSuccess,
916
915
  onError,
917
- onRedirect,
918
916
  ...uiProps
919
917
  }) {
920
918
  const { signIn, baseUrl } = useInsforge();
@@ -940,11 +938,6 @@ function SignIn({
940
938
  if (onSuccess) {
941
939
  if (user) onSuccess(user, accessToken || "");
942
940
  }
943
- if (onRedirect) {
944
- onRedirect(afterSignInUrl);
945
- } else {
946
- window.location.href = afterSignInUrl;
947
- }
948
941
  } catch (err) {
949
942
  const errorMessage = err.message || "Sign in failed";
950
943
  setError(errorMessage);
@@ -958,7 +951,6 @@ function SignIn({
958
951
  setOauthLoading(provider);
959
952
  setError("");
960
953
  const redirectTo = `${window.location.origin}/auth/callback`;
961
- sessionStorage.setItem("oauth_final_destination", afterSignInUrl || "/");
962
954
  await insforge.auth.signInWithOAuth({
963
955
  provider,
964
956
  redirectTo
@@ -1140,10 +1132,8 @@ function SignUpForm({
1140
1132
  );
1141
1133
  }
1142
1134
  function SignUp({
1143
- afterSignUpUrl = "/",
1144
1135
  onSuccess,
1145
1136
  onError,
1146
- onRedirect,
1147
1137
  ...uiProps
1148
1138
  }) {
1149
1139
  const { signUp, baseUrl } = useInsforge();
@@ -1174,11 +1164,6 @@ function SignUp({
1174
1164
  if (onSuccess) {
1175
1165
  if (user) onSuccess(user, accessToken || "");
1176
1166
  }
1177
- if (onRedirect) {
1178
- onRedirect(afterSignUpUrl);
1179
- } else {
1180
- window.location.href = afterSignUpUrl;
1181
- }
1182
1167
  } catch (err) {
1183
1168
  const errorMessage = err.message || "Sign up failed";
1184
1169
  setError(errorMessage);
@@ -1192,7 +1177,6 @@ function SignUp({
1192
1177
  setOauthLoading(provider);
1193
1178
  setError("");
1194
1179
  const redirectTo = `${window.location.origin}/auth/callback`;
1195
- sessionStorage.setItem("oauth_final_destination", afterSignUpUrl || "/");
1196
1180
  await insforge.auth.signInWithOAuth({
1197
1181
  provider,
1198
1182
  redirectTo
@@ -1409,7 +1393,7 @@ function InsforgeCallback({
1409
1393
  onRedirect
1410
1394
  }) {
1411
1395
  const isProcessingRef = react.useRef(false);
1412
- const { reloadAuth } = useInsforge();
1396
+ const { handleAuthCallback } = useInsforge();
1413
1397
  react.useEffect(() => {
1414
1398
  const processCallback = async () => {
1415
1399
  if (isProcessingRef.current) return;
@@ -1429,7 +1413,30 @@ function InsforgeCallback({
1429
1413
  }
1430
1414
  return;
1431
1415
  }
1432
- const result = await reloadAuth();
1416
+ const accessToken = searchParams.get("access_token");
1417
+ const userId = searchParams.get("user_id");
1418
+ const email = searchParams.get("email");
1419
+ const name = searchParams.get("name");
1420
+ if (!accessToken) {
1421
+ const errorMsg = "no_token";
1422
+ if (onError) {
1423
+ onError(errorMsg);
1424
+ } else {
1425
+ const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
1426
+ if (onRedirect) {
1427
+ onRedirect(errorUrl);
1428
+ } else {
1429
+ window.location.href = errorUrl;
1430
+ }
1431
+ }
1432
+ return;
1433
+ }
1434
+ const result = await handleAuthCallback({
1435
+ accessToken,
1436
+ userId: userId || void 0,
1437
+ email: email || void 0,
1438
+ name: name || void 0
1439
+ });
1433
1440
  if (!result.success) {
1434
1441
  const errorMsg = result.error || "authentication_failed";
1435
1442
  if (onError) {
@@ -1458,7 +1465,7 @@ function InsforgeCallback({
1458
1465
  }
1459
1466
  };
1460
1467
  processCallback();
1461
- }, []);
1468
+ }, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
1462
1469
  const defaultLoading = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
1463
1470
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
1464
1471
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })