@insforge/react 1.0.7 → 1.0.9-dev.0

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.
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { InsforgeUser } from '@insforge/shared';
2
3
  import { VerifyEmailResponse } from '@insforge/shared-schemas';
3
4
  import { ReactNode } from 'react';
4
- import { InsforgeUser } from '@insforge/shared';
5
5
  export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.cjs';
6
6
  export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep, AuthErrorBanner, AuthErrorBannerProps, AuthFormField, AuthFormFieldProps, AuthHeader, AuthHeaderProps, AuthLink, AuthLinkProps, AuthOAuthButton, AuthOAuthButtonProps, AuthOAuthProviders, AuthOAuthProvidersProps, AuthPasswordField, AuthPasswordFieldProps, AuthPasswordStrengthIndicator, AuthPasswordStrengthIndicatorProps, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthSubmitButtonProps, AuthVerificationCodeInput, AuthVerificationCodeInputProps } from './atoms.cjs';
7
7
  import './types.cjs';
@@ -21,6 +21,7 @@ interface SignInProps {
21
21
  signUpLinkText?: string;
22
22
  signUpUrl?: string;
23
23
  dividerText?: string;
24
+ onSuccess?: (accessToken: string, user: InsforgeUser, csrfToken?: string | null) => void;
24
25
  onError?: (error: Error) => void;
25
26
  }
26
27
  /**
@@ -30,12 +31,11 @@ interface SignInProps {
30
31
  * @example
31
32
  * ```tsx
32
33
  * <SignIn
33
- * onSuccess={(user) => console.log('Signed in:', user)}
34
34
  * onError={(error) => console.error('Error:', error)}
35
35
  * />
36
36
  * ```
37
37
  */
38
- declare function SignIn({ onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
38
+ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
39
39
 
40
40
  interface SignUpProps {
41
41
  title?: string;
@@ -50,6 +50,7 @@ interface SignUpProps {
50
50
  signInLinkText?: string;
51
51
  signInUrl?: string;
52
52
  dividerText?: string;
53
+ onSuccess?: (accessToken: string, user: InsforgeUser, csrfToken?: string | null) => void;
53
54
  onError?: (error: Error) => void;
54
55
  }
55
56
  /**
@@ -64,7 +65,7 @@ interface SignUpProps {
64
65
  *
65
66
  * ```
66
67
  */
67
- declare function SignUp({ onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
68
+ declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
68
69
 
69
70
  interface ForgotPasswordProps {
70
71
  /** Text customization */
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { InsforgeUser } from '@insforge/shared';
2
3
  import { VerifyEmailResponse } from '@insforge/shared-schemas';
3
4
  import { ReactNode } from 'react';
4
- import { InsforgeUser } from '@insforge/shared';
5
5
  export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.js';
6
6
  export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep, AuthErrorBanner, AuthErrorBannerProps, AuthFormField, AuthFormFieldProps, AuthHeader, AuthHeaderProps, AuthLink, AuthLinkProps, AuthOAuthButton, AuthOAuthButtonProps, AuthOAuthProviders, AuthOAuthProvidersProps, AuthPasswordField, AuthPasswordFieldProps, AuthPasswordStrengthIndicator, AuthPasswordStrengthIndicatorProps, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthSubmitButtonProps, AuthVerificationCodeInput, AuthVerificationCodeInputProps } from './atoms.js';
7
7
  import './types.js';
@@ -21,6 +21,7 @@ interface SignInProps {
21
21
  signUpLinkText?: string;
22
22
  signUpUrl?: string;
23
23
  dividerText?: string;
24
+ onSuccess?: (accessToken: string, user: InsforgeUser, csrfToken?: string | null) => void;
24
25
  onError?: (error: Error) => void;
25
26
  }
26
27
  /**
@@ -30,12 +31,11 @@ interface SignInProps {
30
31
  * @example
31
32
  * ```tsx
32
33
  * <SignIn
33
- * onSuccess={(user) => console.log('Signed in:', user)}
34
34
  * onError={(error) => console.error('Error:', error)}
35
35
  * />
36
36
  * ```
37
37
  */
38
- declare function SignIn({ onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
38
+ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
39
39
 
40
40
  interface SignUpProps {
41
41
  title?: string;
@@ -50,6 +50,7 @@ interface SignUpProps {
50
50
  signInLinkText?: string;
51
51
  signInUrl?: string;
52
52
  dividerText?: string;
53
+ onSuccess?: (accessToken: string, user: InsforgeUser, csrfToken?: string | null) => void;
53
54
  onError?: (error: Error) => void;
54
55
  }
55
56
  /**
@@ -64,7 +65,7 @@ interface SignUpProps {
64
65
  *
65
66
  * ```
66
67
  */
67
- declare function SignUp({ onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
68
+ declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
68
69
 
69
70
  interface ForgotPasswordProps {
70
71
  /** Text customization */
@@ -1752,7 +1752,7 @@ function useInsforge() {
1752
1752
  sendVerificationEmail: () => Promise.resolve(null),
1753
1753
  sendResetPasswordEmail: () => Promise.resolve(null),
1754
1754
  resetPassword: () => Promise.resolve(null),
1755
- verifyEmail: () => Promise.resolve(null),
1755
+ verifyEmail: () => Promise.resolve({ error: "SSR mode" }),
1756
1756
  exchangeResetPasswordToken: () => Promise.resolve({ error: { message: "SSR mode" } }),
1757
1757
  loginWithOAuth: () => Promise.resolve(),
1758
1758
  getPublicAuthConfig: () => Promise.resolve(null),
@@ -3624,7 +3624,7 @@ function SignInForm({
3624
3624
  ] })
3625
3625
  ] });
3626
3626
  }
3627
- function SignIn({ onError, ...uiProps }) {
3627
+ function SignIn({ onSuccess, onError, ...uiProps }) {
3628
3628
  const { signIn, verifyEmail, loginWithOAuth } = useInsforge();
3629
3629
  const { authConfig } = usePublicAuthConfig();
3630
3630
  const [email, setEmail] = useState("");
@@ -3649,19 +3649,12 @@ function SignIn({ onError, ...uiProps }) {
3649
3649
  }
3650
3650
  throw new Error(result.error);
3651
3651
  }
3652
- const { user, accessToken, redirectTo } = result;
3653
- const csrfToken = result.csrfToken;
3654
- if (user) {
3655
- const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
3656
- finalUrl.searchParams.set("access_token", accessToken);
3657
- finalUrl.searchParams.set("user_id", user.id);
3658
- finalUrl.searchParams.set("email", user.email);
3659
- finalUrl.searchParams.set("name", user.profile?.name || "");
3660
- if (csrfToken) {
3661
- finalUrl.searchParams.set("csrf_token", csrfToken);
3662
- }
3663
- window.location.href = finalUrl.toString();
3652
+ const { redirectTo, user, accessToken, csrfToken } = result;
3653
+ if (onSuccess) {
3654
+ onSuccess(accessToken, user, csrfToken);
3664
3655
  }
3656
+ const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
3657
+ window.location.href = finalUrl.toString();
3665
3658
  } catch (err) {
3666
3659
  const errorMessage = err instanceof Error ? err.message : "Sign in failed";
3667
3660
  setError(errorMessage);
@@ -3676,17 +3669,10 @@ function SignIn({ onError, ...uiProps }) {
3676
3669
  setError("");
3677
3670
  try {
3678
3671
  const result = await verifyEmail(code, email);
3679
- if (!result) {
3672
+ if ("error" in result) {
3680
3673
  throw new Error("Verification failed");
3681
3674
  }
3682
3675
  const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
3683
- finalUrl.searchParams.set("access_token", result.accessToken);
3684
- finalUrl.searchParams.set("user_id", result.user.id);
3685
- finalUrl.searchParams.set("email", result.user.email);
3686
- finalUrl.searchParams.set("name", result.user.profile?.name || "");
3687
- if (result.csrfToken) {
3688
- finalUrl.searchParams.set("csrf_token", result.csrfToken);
3689
- }
3690
3676
  window.location.href = finalUrl.toString();
3691
3677
  } catch (err) {
3692
3678
  const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
@@ -3846,7 +3832,7 @@ function createPasswordSchema(options) {
3846
3832
  return schema;
3847
3833
  }
3848
3834
  createPasswordSchema();
3849
- function SignUp({ onError, ...uiProps }) {
3835
+ function SignUp({ onSuccess, onError, ...uiProps }) {
3850
3836
  const { signUp, verifyEmail, loginWithOAuth } = useInsforge();
3851
3837
  const { authConfig } = usePublicAuthConfig();
3852
3838
  const [email, setEmail] = useState("");
@@ -3892,21 +3878,17 @@ function SignUp({ onError, ...uiProps }) {
3892
3878
  if ("error" in result) {
3893
3879
  throw new Error(result.error);
3894
3880
  }
3895
- if (result.requireEmailVerification && !result.accessToken) {
3881
+ if (result.requireEmailVerification) {
3896
3882
  setStep("awaiting-verification");
3897
3883
  setLoading(false);
3898
3884
  return;
3899
3885
  }
3900
- if (result.accessToken && result.user) {
3901
- const csrfToken = result.csrfToken;
3902
- const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
3903
- finalUrl.searchParams.set("access_token", result.accessToken);
3904
- finalUrl.searchParams.set("user_id", result.user.id);
3905
- finalUrl.searchParams.set("email", result.user.email);
3906
- finalUrl.searchParams.set("name", result.user.profile?.name || "");
3907
- if (csrfToken) {
3908
- finalUrl.searchParams.set("csrf_token", csrfToken);
3886
+ const { redirectTo, user, accessToken, csrfToken } = result;
3887
+ if (accessToken && user) {
3888
+ if (onSuccess) {
3889
+ onSuccess(accessToken, user, csrfToken);
3909
3890
  }
3891
+ const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
3910
3892
  window.location.href = finalUrl.toString();
3911
3893
  }
3912
3894
  } catch (err) {
@@ -3923,17 +3905,10 @@ function SignUp({ onError, ...uiProps }) {
3923
3905
  setError("");
3924
3906
  try {
3925
3907
  const result = await verifyEmail(code, email);
3926
- if (!result) {
3908
+ if ("error" in result) {
3927
3909
  throw new Error("Verification failed");
3928
3910
  }
3929
3911
  const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
3930
- finalUrl.searchParams.set("access_token", result.accessToken);
3931
- finalUrl.searchParams.set("user_id", result.user.id);
3932
- finalUrl.searchParams.set("email", result.user.email);
3933
- finalUrl.searchParams.set("name", result.user.profile?.name || "");
3934
- if (result.csrfToken) {
3935
- finalUrl.searchParams.set("csrf_token", result.csrfToken);
3936
- }
3937
3912
  window.location.href = finalUrl.toString();
3938
3913
  } catch (err) {
3939
3914
  const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
@@ -4507,8 +4482,8 @@ function VerifyEmail({ token: token2, onSuccess, onError, ...uiProps }) {
4507
4482
  }
4508
4483
  try {
4509
4484
  const result = await verifyEmail(token2);
4510
- if (!result?.accessToken) {
4511
- const errorMessage = result ? "Verification succeeded but no access token received" : "Email verification failed";
4485
+ if ("error" in result) {
4486
+ const errorMessage = result.error || "Email verification failed";
4512
4487
  setError(errorMessage);
4513
4488
  setStatus("error");
4514
4489
  if (onError) {