@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.
@@ -909,10 +909,8 @@ function SignInForm({
909
909
  );
910
910
  }
911
911
  function SignIn({
912
- afterSignInUrl = "/",
913
912
  onSuccess,
914
913
  onError,
915
- onRedirect,
916
914
  ...uiProps
917
915
  }) {
918
916
  const { signIn, baseUrl } = useInsforge();
@@ -938,11 +936,6 @@ function SignIn({
938
936
  if (onSuccess) {
939
937
  if (user) onSuccess(user, accessToken || "");
940
938
  }
941
- if (onRedirect) {
942
- onRedirect(afterSignInUrl);
943
- } else {
944
- window.location.href = afterSignInUrl;
945
- }
946
939
  } catch (err) {
947
940
  const errorMessage = err.message || "Sign in failed";
948
941
  setError(errorMessage);
@@ -956,7 +949,6 @@ function SignIn({
956
949
  setOauthLoading(provider);
957
950
  setError("");
958
951
  const redirectTo = `${window.location.origin}/auth/callback`;
959
- sessionStorage.setItem("oauth_final_destination", afterSignInUrl || "/");
960
952
  await insforge.auth.signInWithOAuth({
961
953
  provider,
962
954
  redirectTo
@@ -1138,10 +1130,8 @@ function SignUpForm({
1138
1130
  );
1139
1131
  }
1140
1132
  function SignUp({
1141
- afterSignUpUrl = "/",
1142
1133
  onSuccess,
1143
1134
  onError,
1144
- onRedirect,
1145
1135
  ...uiProps
1146
1136
  }) {
1147
1137
  const { signUp, baseUrl } = useInsforge();
@@ -1172,11 +1162,6 @@ function SignUp({
1172
1162
  if (onSuccess) {
1173
1163
  if (user) onSuccess(user, accessToken || "");
1174
1164
  }
1175
- if (onRedirect) {
1176
- onRedirect(afterSignUpUrl);
1177
- } else {
1178
- window.location.href = afterSignUpUrl;
1179
- }
1180
1165
  } catch (err) {
1181
1166
  const errorMessage = err.message || "Sign up failed";
1182
1167
  setError(errorMessage);
@@ -1190,7 +1175,6 @@ function SignUp({
1190
1175
  setOauthLoading(provider);
1191
1176
  setError("");
1192
1177
  const redirectTo = `${window.location.origin}/auth/callback`;
1193
- sessionStorage.setItem("oauth_final_destination", afterSignUpUrl || "/");
1194
1178
  await insforge.auth.signInWithOAuth({
1195
1179
  provider,
1196
1180
  redirectTo
@@ -1407,7 +1391,7 @@ function InsforgeCallback({
1407
1391
  onRedirect
1408
1392
  }) {
1409
1393
  const isProcessingRef = useRef(false);
1410
- const { reloadAuth } = useInsforge();
1394
+ const { handleAuthCallback } = useInsforge();
1411
1395
  useEffect(() => {
1412
1396
  const processCallback = async () => {
1413
1397
  if (isProcessingRef.current) return;
@@ -1427,7 +1411,30 @@ function InsforgeCallback({
1427
1411
  }
1428
1412
  return;
1429
1413
  }
1430
- const result = await reloadAuth();
1414
+ const accessToken = searchParams.get("access_token");
1415
+ const userId = searchParams.get("user_id");
1416
+ const email = searchParams.get("email");
1417
+ const name = searchParams.get("name");
1418
+ if (!accessToken) {
1419
+ const errorMsg = "no_token";
1420
+ if (onError) {
1421
+ onError(errorMsg);
1422
+ } else {
1423
+ const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
1424
+ if (onRedirect) {
1425
+ onRedirect(errorUrl);
1426
+ } else {
1427
+ window.location.href = errorUrl;
1428
+ }
1429
+ }
1430
+ return;
1431
+ }
1432
+ const result = await handleAuthCallback({
1433
+ accessToken,
1434
+ userId: userId || void 0,
1435
+ email: email || void 0,
1436
+ name: name || void 0
1437
+ });
1431
1438
  if (!result.success) {
1432
1439
  const errorMsg = result.error || "authentication_failed";
1433
1440
  if (onError) {
@@ -1456,7 +1463,7 @@ function InsforgeCallback({
1456
1463
  }
1457
1464
  };
1458
1465
  processCallback();
1459
- }, []);
1466
+ }, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
1460
1467
  const defaultLoading = /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
1461
1468
  /* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
1462
1469
  /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })