@insforge/react 0.3.2 → 0.3.4

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
@@ -252,9 +252,9 @@ function InsforgeProvider({
252
252
  },
253
253
  [user, onAuthChange, insforge]
254
254
  );
255
- const sendPasswordResetCode = useCallback(
255
+ const sendResetPasswordEmail = useCallback(
256
256
  async (email) => {
257
- const sdkResult = await insforge.auth.sendPasswordResetCode({ email });
257
+ const sdkResult = await insforge.auth.sendResetPasswordEmail({ email });
258
258
  return sdkResult.data;
259
259
  },
260
260
  [insforge]
@@ -290,7 +290,7 @@ function InsforgeProvider({
290
290
  updateUser,
291
291
  reloadAuth: loadAuthState,
292
292
  baseUrl,
293
- sendPasswordResetCode,
293
+ sendResetPasswordEmail,
294
294
  resetPassword,
295
295
  verifyEmail,
296
296
  getPublicAuthConfig
@@ -308,22 +308,22 @@ function useInsforge() {
308
308
  }
309
309
  function usePublicAuthConfig() {
310
310
  const { getPublicAuthConfig } = useInsforge();
311
- const [emailConfig, setEmailConfig] = useState(null);
311
+ const [authConfig, setAuthConfig] = useState(null);
312
312
  const [isLoaded, setIsLoaded] = useState(false);
313
313
  useEffect(() => {
314
314
  async function fetchConfig() {
315
315
  const result = await getPublicAuthConfig();
316
316
  if (result) {
317
- setEmailConfig(result);
317
+ setAuthConfig(result);
318
318
  } else {
319
319
  console.error("[usePublicAuthConfig] Failed to get public auth config");
320
- setEmailConfig(null);
320
+ setAuthConfig(null);
321
321
  }
322
322
  setIsLoaded(true);
323
323
  }
324
324
  fetchConfig();
325
325
  }, [getPublicAuthConfig]);
326
- return { emailConfig, isLoaded };
326
+ return { authConfig, isLoaded };
327
327
  }
328
328
  function AuthBranding() {
329
329
  return /* @__PURE__ */ jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
@@ -560,7 +560,7 @@ function AuthPasswordField({
560
560
  label,
561
561
  id,
562
562
  showStrengthIndicator = false,
563
- emailAuthConfig,
563
+ authConfig,
564
564
  forgotPasswordLink,
565
565
  value,
566
566
  appearance = {},
@@ -638,7 +638,7 @@ function AuthPasswordField({
638
638
  AuthPasswordStrengthIndicator,
639
639
  {
640
640
  password: String(value || ""),
641
- config: emailAuthConfig
641
+ config: authConfig
642
642
  }
643
643
  )
644
644
  ]
@@ -1075,11 +1075,7 @@ function AuthEmailVerificationStep({
1075
1075
  useEffect(() => {
1076
1076
  const sendInitialEmail = async () => {
1077
1077
  try {
1078
- if (method === "code") {
1079
- await insforge.auth.sendVerificationCode({ email });
1080
- } else {
1081
- await insforge.auth.sendVerificationLink({ email });
1082
- }
1078
+ await insforge.auth.sendVerificationEmail({ email });
1083
1079
  } catch {
1084
1080
  }
1085
1081
  };
@@ -1105,11 +1101,7 @@ function AuthEmailVerificationStep({
1105
1101
  setIsSending(true);
1106
1102
  setVerificationError("");
1107
1103
  try {
1108
- if (method === "code") {
1109
- await insforge.auth.sendVerificationCode({ email });
1110
- } else {
1111
- await insforge.auth.sendVerificationLink({ email });
1112
- }
1104
+ await insforge.auth.sendVerificationEmail({ email });
1113
1105
  } catch {
1114
1106
  setResendDisabled(false);
1115
1107
  setResendCountdown(0);
@@ -1187,7 +1179,7 @@ function SignInForm({
1187
1179
  oauthLoading = null,
1188
1180
  availableProviders = [],
1189
1181
  onOAuthClick,
1190
- emailAuthConfig,
1182
+ authConfig,
1191
1183
  appearance = {},
1192
1184
  title = "Welcome Back",
1193
1185
  subtitle = "Login to your account",
@@ -1277,7 +1269,7 @@ function SignInForm({
1277
1269
  onChange: (e) => onPasswordChange(e.target.value),
1278
1270
  required: true,
1279
1271
  autoComplete: "current-password",
1280
- emailAuthConfig,
1272
+ authConfig,
1281
1273
  forgotPasswordLink: forgotPasswordUrl ? {
1282
1274
  href: forgotPasswordUrl,
1283
1275
  text: forgotPasswordText
@@ -1348,7 +1340,7 @@ function SignIn({
1348
1340
  ...uiProps
1349
1341
  }) {
1350
1342
  const { signIn, baseUrl } = useInsforge();
1351
- const { emailConfig } = usePublicAuthConfig();
1343
+ const { authConfig } = usePublicAuthConfig();
1352
1344
  const [email, setEmail] = useState("");
1353
1345
  const [password, setPassword] = useState("");
1354
1346
  const [error, setError] = useState("");
@@ -1372,9 +1364,9 @@ function SignIn({
1372
1364
  }
1373
1365
  throw new Error(result.error);
1374
1366
  }
1375
- const { user, accessToken } = result;
1367
+ const { user, accessToken, redirectTo } = result;
1376
1368
  if (onSuccess) {
1377
- if (user) onSuccess(user, accessToken || "");
1369
+ if (user) onSuccess(user, accessToken || "", redirectTo);
1378
1370
  }
1379
1371
  } catch (err) {
1380
1372
  const errorMessage = err.message || "Sign in failed";
@@ -1414,7 +1406,7 @@ function SignIn({
1414
1406
  setOauthLoading(null);
1415
1407
  }
1416
1408
  }
1417
- if (!emailConfig) {
1409
+ if (!authConfig) {
1418
1410
  return null;
1419
1411
  }
1420
1412
  return /* @__PURE__ */ jsx(
@@ -1428,9 +1420,9 @@ function SignIn({
1428
1420
  error,
1429
1421
  loading,
1430
1422
  oauthLoading,
1431
- availableProviders: emailConfig?.oAuthProviders || [],
1423
+ availableProviders: authConfig?.oAuthProviders || [],
1432
1424
  onOAuthClick: handleOAuth,
1433
- emailAuthConfig: emailConfig,
1425
+ authConfig,
1434
1426
  showVerificationStep: step === "awaiting-verification",
1435
1427
  onVerifyCode: handleVerifyCode,
1436
1428
  ...uiProps
@@ -1448,7 +1440,7 @@ function SignUpForm({
1448
1440
  oauthLoading = null,
1449
1441
  availableProviders = [],
1450
1442
  onOAuthClick,
1451
- emailAuthConfig,
1443
+ authConfig,
1452
1444
  appearance = {},
1453
1445
  title = "Get Started",
1454
1446
  subtitle = "Create your account",
@@ -1535,10 +1527,10 @@ function SignUpForm({
1535
1527
  value: password,
1536
1528
  onChange: (e) => onPasswordChange(e.target.value),
1537
1529
  required: true,
1538
- minLength: emailAuthConfig.passwordMinLength,
1530
+ minLength: authConfig.passwordMinLength,
1539
1531
  autoComplete: "new-password",
1540
1532
  showStrengthIndicator: true,
1541
- emailAuthConfig,
1533
+ authConfig,
1542
1534
  appearance: {
1543
1535
  containerClassName: appearance.form?.passwordField?.container,
1544
1536
  labelClassName: appearance.form?.passwordField?.label,
@@ -1676,7 +1668,7 @@ function SignUp({
1676
1668
  ...uiProps
1677
1669
  }) {
1678
1670
  const { signUp, baseUrl } = useInsforge();
1679
- const { emailConfig } = usePublicAuthConfig();
1671
+ const { authConfig } = usePublicAuthConfig();
1680
1672
  const [email, setEmail] = useState("");
1681
1673
  const [password, setPassword] = useState("");
1682
1674
  const [error, setError] = useState("");
@@ -1690,7 +1682,7 @@ function SignUp({
1690
1682
  e.preventDefault();
1691
1683
  setLoading(true);
1692
1684
  setError("");
1693
- if (!emailConfig) {
1685
+ if (!authConfig) {
1694
1686
  setError("Configuration not loaded. Please refresh the page.");
1695
1687
  setLoading(false);
1696
1688
  return;
@@ -1703,11 +1695,11 @@ function SignUp({
1703
1695
  return;
1704
1696
  }
1705
1697
  const passwordZodSchema = createPasswordSchema({
1706
- minLength: emailConfig.passwordMinLength,
1707
- requireUppercase: emailConfig.requireUppercase,
1708
- requireLowercase: emailConfig.requireLowercase,
1709
- requireNumber: emailConfig.requireNumber,
1710
- requireSpecialChar: emailConfig.requireSpecialChar
1698
+ minLength: authConfig.passwordMinLength,
1699
+ requireUppercase: authConfig.requireUppercase,
1700
+ requireLowercase: authConfig.requireLowercase,
1701
+ requireNumber: authConfig.requireNumber,
1702
+ requireSpecialChar: authConfig.requireSpecialChar
1711
1703
  });
1712
1704
  const passwordValidation = passwordZodSchema.safeParse(password);
1713
1705
  if (!passwordValidation.success) {
@@ -1728,7 +1720,7 @@ function SignUp({
1728
1720
  }
1729
1721
  if (result.accessToken && result.user) {
1730
1722
  if (onSuccess) {
1731
- onSuccess(result.user, result.accessToken);
1723
+ onSuccess(result.user, result.accessToken, result.redirectTo);
1732
1724
  }
1733
1725
  }
1734
1726
  } catch (err) {
@@ -1769,7 +1761,7 @@ function SignUp({
1769
1761
  setOauthLoading(null);
1770
1762
  }
1771
1763
  }
1772
- if (!emailConfig) {
1764
+ if (!authConfig) {
1773
1765
  return null;
1774
1766
  }
1775
1767
  return /* @__PURE__ */ jsx(
@@ -1783,9 +1775,9 @@ function SignUp({
1783
1775
  error,
1784
1776
  loading,
1785
1777
  oauthLoading,
1786
- availableProviders: emailConfig?.oAuthProviders || [],
1778
+ availableProviders: authConfig?.oAuthProviders || [],
1787
1779
  onOAuthClick: handleOAuth,
1788
- emailAuthConfig: emailConfig,
1780
+ authConfig,
1789
1781
  showVerificationStep: step === "awaiting-verification",
1790
1782
  onVerifyCode: handleVerifyCode,
1791
1783
  ...uiProps
@@ -1917,7 +1909,7 @@ function ResetPasswordForm({
1917
1909
  error,
1918
1910
  loading = false,
1919
1911
  success = false,
1920
- emailAuthConfig,
1912
+ authConfig,
1921
1913
  appearance = {},
1922
1914
  title = "Reset Password",
1923
1915
  subtitle = "Enter your new password below.",
@@ -1994,7 +1986,7 @@ function ResetPasswordForm({
1994
1986
  required: true,
1995
1987
  autoComplete: "new-password",
1996
1988
  showStrengthIndicator: true,
1997
- emailAuthConfig,
1989
+ authConfig,
1998
1990
  appearance: {
1999
1991
  containerClassName: appearance.form?.newPasswordField?.container,
2000
1992
  labelClassName: appearance.form?.newPasswordField?.label,
@@ -2012,7 +2004,7 @@ function ResetPasswordForm({
2012
2004
  onChange: (e) => onConfirmPasswordChange(e.target.value),
2013
2005
  required: true,
2014
2006
  autoComplete: "new-password",
2015
- emailAuthConfig,
2007
+ authConfig,
2016
2008
  appearance: {
2017
2009
  containerClassName: appearance.form?.confirmPasswordField?.container,
2018
2010
  labelClassName: appearance.form?.confirmPasswordField?.label,
@@ -2056,7 +2048,7 @@ function ResetPassword({
2056
2048
  ...uiProps
2057
2049
  }) {
2058
2050
  const { resetPassword } = useInsforge();
2059
- const { emailConfig } = usePublicAuthConfig();
2051
+ const { authConfig } = usePublicAuthConfig();
2060
2052
  const [newPassword, setNewPassword] = useState("");
2061
2053
  const [confirmPassword, setConfirmPassword] = useState("");
2062
2054
  const [error, setError] = useState("");
@@ -2066,7 +2058,7 @@ function ResetPassword({
2066
2058
  e.preventDefault();
2067
2059
  setLoading(true);
2068
2060
  setError("");
2069
- if (!emailConfig) {
2061
+ if (!authConfig) {
2070
2062
  setError("Configuration not loaded. Please refresh the page.");
2071
2063
  setLoading(false);
2072
2064
  return;
@@ -2082,11 +2074,11 @@ function ResetPassword({
2082
2074
  return;
2083
2075
  }
2084
2076
  const passwordZodSchema = createPasswordSchema({
2085
- minLength: emailConfig.passwordMinLength,
2086
- requireUppercase: emailConfig.requireUppercase,
2087
- requireLowercase: emailConfig.requireLowercase,
2088
- requireNumber: emailConfig.requireNumber,
2089
- requireSpecialChar: emailConfig.requireSpecialChar
2077
+ minLength: authConfig.passwordMinLength,
2078
+ requireUppercase: authConfig.requireUppercase,
2079
+ requireLowercase: authConfig.requireLowercase,
2080
+ requireNumber: authConfig.requireNumber,
2081
+ requireSpecialChar: authConfig.requireSpecialChar
2090
2082
  });
2091
2083
  const passwordValidation = passwordZodSchema.safeParse(newPassword);
2092
2084
  if (!passwordValidation.success) {
@@ -2100,7 +2092,7 @@ function ResetPassword({
2100
2092
  if (result?.message) {
2101
2093
  setSuccess(true);
2102
2094
  if (onSuccess) {
2103
- onSuccess(result.redirectTo);
2095
+ onSuccess();
2104
2096
  }
2105
2097
  } else {
2106
2098
  const errorMessage = "Failed to reset password";
@@ -2119,7 +2111,7 @@ function ResetPassword({
2119
2111
  setLoading(false);
2120
2112
  }
2121
2113
  }
2122
- if (!emailConfig) {
2114
+ if (!authConfig) {
2123
2115
  return null;
2124
2116
  }
2125
2117
  return /* @__PURE__ */ jsx(
@@ -2133,7 +2125,7 @@ function ResetPassword({
2133
2125
  error,
2134
2126
  loading,
2135
2127
  success,
2136
- emailAuthConfig: emailConfig,
2128
+ authConfig,
2137
2129
  backToSignInUrl,
2138
2130
  ...uiProps
2139
2131
  }
@@ -2145,8 +2137,8 @@ function ForgotPassword({
2145
2137
  onError,
2146
2138
  ...uiProps
2147
2139
  }) {
2148
- const { sendPasswordResetCode, baseUrl } = useInsforge();
2149
- const { emailConfig } = usePublicAuthConfig();
2140
+ const { sendResetPasswordEmail, baseUrl } = useInsforge();
2141
+ const { authConfig } = usePublicAuthConfig();
2150
2142
  const [insforge] = useState(() => createClient({ baseUrl }));
2151
2143
  const [step, setStep] = useState("email");
2152
2144
  const [email, setEmail] = useState("");
@@ -2185,9 +2177,9 @@ function ForgotPassword({
2185
2177
  return;
2186
2178
  }
2187
2179
  try {
2188
- const result = await sendPasswordResetCode(emailValidation.data);
2180
+ const result = await sendResetPasswordEmail(emailValidation.data);
2189
2181
  if (result?.success) {
2190
- if (emailConfig?.resetPasswordMethod === "link") {
2182
+ if (authConfig?.resetPasswordMethod === "link") {
2191
2183
  setSuccess(true);
2192
2184
  if (onSuccess) {
2193
2185
  onSuccess();
@@ -2240,7 +2232,7 @@ function ForgotPassword({
2240
2232
  setIsSendingCode(true);
2241
2233
  setError("");
2242
2234
  try {
2243
- await sendPasswordResetCode(email);
2235
+ await sendResetPasswordEmail(email);
2244
2236
  } catch (err) {
2245
2237
  setError(err.message || "Failed to resend code");
2246
2238
  setResendDisabled(false);
@@ -2248,7 +2240,7 @@ function ForgotPassword({
2248
2240
  } finally {
2249
2241
  setIsSendingCode(false);
2250
2242
  }
2251
- }, [email, sendPasswordResetCode]);
2243
+ }, [email, sendResetPasswordEmail]);
2252
2244
  function handlePasswordResetSuccess(redirectTo) {
2253
2245
  const targetUrl = redirectTo || backToSignInUrl;
2254
2246
  if (onSuccess) {
@@ -2258,7 +2250,7 @@ function ForgotPassword({
2258
2250
  window.location.href = targetUrl;
2259
2251
  }, 1500);
2260
2252
  }
2261
- if (!emailConfig) {
2253
+ if (!authConfig) {
2262
2254
  return null;
2263
2255
  }
2264
2256
  if (step === "email") {
@@ -2411,7 +2403,8 @@ function VerifyEmail({
2411
2403
  if (onSuccess) {
2412
2404
  onSuccess({
2413
2405
  accessToken: result.accessToken,
2414
- user: result.user
2406
+ user: result.user,
2407
+ redirectTo: result.redirectTo
2415
2408
  });
2416
2409
  }
2417
2410
  } catch (err) {