@insforge/react 0.4.7 → 0.4.9

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/forms.cjs CHANGED
@@ -108,34 +108,27 @@ function AuthPasswordStrengthIndicator({
108
108
  config
109
109
  }) {
110
110
  const requirements = createRequirements(config);
111
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-passwordStrength if-internal-ps6w3k", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-passwordStrength-requirements", children: requirements.map((req) => /* @__PURE__ */ jsxRuntime.jsxs(
112
- "div",
113
- {
114
- className: `if-passwordStrength-requirement ${req.test(password) ? "met" : "unmet"}`,
115
- children: [
116
- /* @__PURE__ */ jsxRuntime.jsx(
117
- "div",
118
- {
119
- style: {
120
- display: "flex",
121
- alignItems: "center",
122
- justifyContent: "center",
123
- width: "1rem",
124
- height: "1rem",
125
- borderRadius: "50%",
126
- border: "2px solid",
127
- borderColor: req.test(password) ? "transparent" : "#9ca3af",
128
- backgroundColor: req.test(password) ? "#059669" : "white",
129
- transition: "all 0.2s"
130
- },
131
- children: req.test(password) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { style: { width: "0.75rem", height: "0.75rem", color: "white" } })
132
- }
133
- ),
134
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: req.label })
135
- ]
136
- },
137
- req.label
138
- )) }) });
111
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-passwordStrength if-internal-ps6w3k", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-passwordStrength-requirements", children: requirements.map((req) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordStrength-requirement", children: [
112
+ /* @__PURE__ */ jsxRuntime.jsx(
113
+ "div",
114
+ {
115
+ style: {
116
+ display: "flex",
117
+ alignItems: "center",
118
+ justifyContent: "center",
119
+ width: "1rem",
120
+ height: "1rem",
121
+ borderRadius: "50%",
122
+ border: "2px solid",
123
+ borderColor: req.test(password) ? "transparent" : "#9ca3af",
124
+ backgroundColor: req.test(password) ? "#059669" : "white",
125
+ transition: "all 0.2s"
126
+ },
127
+ children: req.test(password) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { style: { width: "0.75rem", height: "0.75rem", color: "white" } })
128
+ }
129
+ ),
130
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: req.label })
131
+ ] }, req.label)) }) });
139
132
  }
140
133
  function createRequirements(config) {
141
134
  const requirements = [];
@@ -203,11 +196,12 @@ function AuthPasswordField({
203
196
  onFocus,
204
197
  ...props
205
198
  }) {
199
+ const [searchParams] = reactRouterDom.useSearchParams();
206
200
  const [showPassword, setShowPassword] = react.useState(false);
207
201
  const [showStrength, setShowStrength] = react.useState(false);
208
202
  const resolvedForgotPasswordHref = react.useMemo(
209
- () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
210
- [forgotPasswordLink]
203
+ () => forgotPasswordLink ? resolveAuthUrl(forgotPasswordLink.href, searchParams) : void 0,
204
+ [forgotPasswordLink, searchParams]
211
205
  );
212
206
  const handleFocus = (e) => {
213
207
  if (showStrengthIndicator) {
@@ -545,7 +539,6 @@ function AuthOAuthProviders({
545
539
  function AuthVerificationCodeInput({
546
540
  length = 6,
547
541
  value,
548
- email,
549
542
  onChange,
550
543
  disabled = false,
551
544
  onComplete
@@ -593,33 +586,25 @@ function AuthVerificationCodeInput({
593
586
  }
594
587
  }
595
588
  };
596
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationCode if-internal-vc8m4p", children: [
597
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-verificationCode-description", children: [
598
- "We've sent a verification code to your inbox at",
599
- " ",
600
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email }),
601
- ". Enter it below to proceed."
602
- ] }),
603
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
604
- "input",
605
- {
606
- ref: (el) => {
607
- inputRefs.current[index] = el;
608
- },
609
- type: "text",
610
- inputMode: "numeric",
611
- maxLength: 1,
612
- value: value[index] || "",
613
- onChange: (e) => handleChange(index, e.target.value),
614
- onKeyDown: (e) => handleKeyDown(index, e),
615
- onPaste: handlePaste,
616
- disabled,
617
- className: "if-verificationCode-input",
618
- autoComplete: "one-time-code"
589
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
590
+ "input",
591
+ {
592
+ ref: (el) => {
593
+ inputRefs.current[index] = el;
619
594
  },
620
- index
621
- )) })
622
- ] });
595
+ type: "text",
596
+ inputMode: "numeric",
597
+ maxLength: 1,
598
+ value: value[index] || "",
599
+ onChange: (e) => handleChange(index, e.target.value),
600
+ onKeyDown: (e) => handleKeyDown(index, e),
601
+ onPaste: handlePaste,
602
+ disabled,
603
+ className: "if-verificationCode-input",
604
+ autoComplete: "one-time-code"
605
+ },
606
+ index
607
+ )) });
623
608
  }
624
609
  var InsforgeContext = react.createContext(void 0);
625
610
  function useInsforge() {
@@ -631,28 +616,20 @@ function useInsforge() {
631
616
  }
632
617
  function AuthEmailVerificationStep({
633
618
  email,
634
- method = "code",
635
- onVerifyCode
619
+ method,
620
+ onVerifyCode,
621
+ emailSent = false
636
622
  }) {
637
623
  const { sendVerificationEmail } = useInsforge();
638
624
  const [resendDisabled, setResendDisabled] = react.useState(true);
639
- const [resendCountdown, setResendCountdown] = react.useState(60);
625
+ const [resendCountdown, setResendCountdown] = react.useState(emailSent ? 60 : 0);
640
626
  const [isSending, setIsSending] = react.useState(false);
641
627
  const [verificationCode, setVerificationCode] = react.useState("");
642
628
  const [isVerifying, setIsVerifying] = react.useState(false);
643
- const defaultDescription = method === "code" ? "We've sent a 6-digit verification code to {email}. Please enter it below to verify your account. The code will expire in 10 minutes." : "We've sent a verification link to {email}. Please check your email and click the link to verify your account. The link will expire in 10 minutes.";
644
- react.useEffect(() => {
645
- const sendInitialEmail = async () => {
646
- try {
647
- await sendVerificationEmail(email);
648
- } catch (error) {
649
- console.error("Failed to send verification email:", error);
650
- }
651
- };
652
- void sendInitialEmail();
653
- }, [email, sendVerificationEmail]);
629
+ const isLinkMethod = method === "link";
630
+ const displayDescription = isLinkMethod ? "We've sent an email to {email}. Please check your email to confirm your account before signing in. The confirmation link expires in 10 minutes." : "We've sent a verification code to your inbox at {email}. Enter it below to proceed.";
654
631
  react.useEffect(() => {
655
- if (resendCountdown > 0) {
632
+ if (emailSent && resendCountdown > 0) {
656
633
  const timer = setInterval(() => {
657
634
  setResendCountdown((prev) => {
658
635
  if (prev <= 1) {
@@ -664,7 +641,7 @@ function AuthEmailVerificationStep({
664
641
  }, 1e3);
665
642
  return () => clearInterval(timer);
666
643
  }
667
- }, [resendCountdown]);
644
+ }, [emailSent, resendCountdown]);
668
645
  const handleResend = async () => {
669
646
  setResendDisabled(true);
670
647
  setResendCountdown(60);
@@ -690,23 +667,29 @@ function AuthEmailVerificationStep({
690
667
  setVerificationCode("");
691
668
  }
692
669
  };
693
- const displayDescription = defaultDescription;
694
- const isLinkMethod = method === "link";
695
670
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
696
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
697
- part,
698
- index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
699
- ] }, index)) }),
671
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
672
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Verify Your Email" }),
673
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
674
+ part,
675
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
676
+ ] }, index)) })
677
+ ] }),
700
678
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
701
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
702
- AuthVerificationCodeInput,
703
- {
704
- value: verificationCode,
705
- onChange: setVerificationCode,
706
- email,
707
- disabled: isVerifying
708
- }
709
- ) }),
679
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeInputWrapper", children: [
680
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-codeDescription", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
681
+ part,
682
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
683
+ ] }, index)) }),
684
+ /* @__PURE__ */ jsxRuntime.jsx(
685
+ AuthVerificationCodeInput,
686
+ {
687
+ value: verificationCode,
688
+ onChange: setVerificationCode,
689
+ disabled: isVerifying
690
+ }
691
+ )
692
+ ] }),
710
693
  /* @__PURE__ */ jsxRuntime.jsx(
711
694
  AuthSubmitButton,
712
695
  {
@@ -716,7 +699,7 @@ function AuthEmailVerificationStep({
716
699
  onClick: () => {
717
700
  void handleSubmit();
718
701
  },
719
- children: isVerifying ? "Verifying..." : "Verify Code"
702
+ children: isVerifying ? "Verifying..." : "Continue"
720
703
  }
721
704
  )
722
705
  ] }),
@@ -748,6 +731,8 @@ function AuthResetPasswordVerificationStep({
748
731
  const [isSending, setIsSending] = react.useState(false);
749
732
  const [verificationCode, setVerificationCode] = react.useState("");
750
733
  const [isVerifying, setIsVerifying] = react.useState(false);
734
+ const isLinkMethod = method === "link";
735
+ const displayDescription = isLinkMethod ? "We have sent an email to {email}. Please check your email to reset your password. The link expires in 10 minutes." : "We've sent a reset password code to your inbox at {email}. Enter it below to proceed.";
751
736
  react.useEffect(() => {
752
737
  if (resendCountdown > 0) {
753
738
  const timer = setInterval(() => {
@@ -787,17 +772,20 @@ function AuthResetPasswordVerificationStep({
787
772
  setVerificationCode("");
788
773
  }
789
774
  };
790
- const isLinkMethod = method === "link";
791
- const description = isLinkMethod ? `We've sent a password reset link to ${email}. Please check your email and click the link to reset your password. The link will expire in 10 minutes.` : `We've sent a 6-digit verification code to ${email}. Please enter it below to reset your password. The code will expire in 10 minutes.`;
792
775
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
793
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: description }),
776
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
777
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Check Your Email" }),
778
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
779
+ part,
780
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
781
+ ] }, index)) })
782
+ ] }),
794
783
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
795
784
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
796
785
  AuthVerificationCodeInput,
797
786
  {
798
787
  value: verificationCode,
799
788
  onChange: setVerificationCode,
800
- email,
801
789
  disabled: isVerifying
802
790
  }
803
791
  ) }),
@@ -840,7 +828,6 @@ function SignInForm({
840
828
  error,
841
829
  loading = false,
842
830
  oauthLoading = null,
843
- availableProviders = [],
844
831
  onOAuthClick,
845
832
  authConfig,
846
833
  title = "Welcome Back",
@@ -850,7 +837,7 @@ function SignInForm({
850
837
  passwordLabel = "Password",
851
838
  passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
852
839
  forgotPasswordText = "Forget Password?",
853
- forgotPasswordUrl,
840
+ forgotPasswordUrl = "/forgot-password",
854
841
  submitButtonText = "Sign In",
855
842
  loadingButtonText = "Signing in...",
856
843
  signUpText = "Don't have an account?",
@@ -861,15 +848,17 @@ function SignInForm({
861
848
  onVerifyCode
862
849
  }) {
863
850
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
864
- /* @__PURE__ */ jsxRuntime.jsx(
865
- AuthHeader,
851
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
852
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
853
+ showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
854
+ AuthEmailVerificationStep,
866
855
  {
867
- title: showVerificationStep ? "Verify Your Email" : title,
868
- subtitle: showVerificationStep ? "" : subtitle
856
+ email,
857
+ method: authConfig.verifyEmailMethod,
858
+ onVerifyCode,
859
+ emailSent: false
869
860
  }
870
- ),
871
- /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
872
- showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
861
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
873
862
  /* @__PURE__ */ jsxRuntime.jsx(
874
863
  AuthFormField,
875
864
  {
@@ -904,12 +893,12 @@ function SignInForm({
904
893
  ] }),
905
894
  !showVerificationStep && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
906
895
  /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signUpText, linkText: signUpLinkText, href: signUpUrl }),
907
- availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
896
+ authConfig.oAuthProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
908
897
  /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
909
898
  /* @__PURE__ */ jsxRuntime.jsx(
910
899
  AuthOAuthProviders,
911
900
  {
912
- providers: availableProviders,
901
+ providers: authConfig.oAuthProviders,
913
902
  onClick: onOAuthClick,
914
903
  disabled: loading || oauthLoading !== null,
915
904
  loading: oauthLoading
@@ -928,7 +917,6 @@ function SignUpForm({
928
917
  error,
929
918
  loading = false,
930
919
  oauthLoading = null,
931
- availableProviders = [],
932
920
  onOAuthClick,
933
921
  authConfig,
934
922
  title = "Get Started",
@@ -947,15 +935,17 @@ function SignUpForm({
947
935
  onVerifyCode
948
936
  }) {
949
937
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
950
- /* @__PURE__ */ jsxRuntime.jsx(
951
- AuthHeader,
938
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
939
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
940
+ showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
941
+ AuthEmailVerificationStep,
952
942
  {
953
- title: showVerificationStep ? "Verify Your Email" : title,
954
- subtitle: showVerificationStep ? "" : subtitle
943
+ email,
944
+ method: authConfig.verifyEmailMethod,
945
+ onVerifyCode,
946
+ emailSent: true
955
947
  }
956
- ),
957
- /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
958
- showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
948
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
959
949
  /* @__PURE__ */ jsxRuntime.jsx(
960
950
  AuthFormField,
961
951
  {
@@ -978,7 +968,6 @@ function SignUpForm({
978
968
  value: password,
979
969
  onChange: (e) => onPasswordChange(e.target.value),
980
970
  required: true,
981
- minLength: authConfig.passwordMinLength,
982
971
  autoComplete: "new-password",
983
972
  showStrengthIndicator: true,
984
973
  authConfig
@@ -988,12 +977,12 @@ function SignUpForm({
988
977
  ] }),
989
978
  !showVerificationStep && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
990
979
  /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signInText, linkText: signInLinkText, href: signInUrl }),
991
- availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
980
+ authConfig.oAuthProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
992
981
  /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
993
982
  /* @__PURE__ */ jsxRuntime.jsx(
994
983
  AuthOAuthProviders,
995
984
  {
996
- providers: availableProviders,
985
+ providers: authConfig.oAuthProviders,
997
986
  onClick: onOAuthClick,
998
987
  disabled: loading || oauthLoading !== null,
999
988
  loading: oauthLoading
@@ -1010,10 +999,10 @@ function ForgotPasswordForm({
1010
999
  error,
1011
1000
  loading = false,
1012
1001
  title = "Forgot Password?",
1013
- subtitle = "Enter your email address and we'll send you a code to reset your password.",
1002
+ subtitle = "Enter your email address and we'll send you a {method} to reset your password.",
1014
1003
  emailLabel = "Email",
1015
1004
  emailPlaceholder = "example@email.com",
1016
- submitButtonText = "Send Reset Code",
1005
+ submitButtonText = "Reset Password",
1017
1006
  loadingButtonText = "Sending...",
1018
1007
  backToSignInText = "Remember your password?",
1019
1008
  backToSignInUrl = "/sign-in",
@@ -1022,14 +1011,9 @@ function ForgotPasswordForm({
1022
1011
  onVerifyCode,
1023
1012
  onResendEmail
1024
1013
  }) {
1014
+ const displaySubtitle = subtitle.replace("{method}", resetPasswordMethod);
1025
1015
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
1026
- /* @__PURE__ */ jsxRuntime.jsx(
1027
- AuthHeader,
1028
- {
1029
- title: showVerificationStep ? resetPasswordMethod === "link" ? "Check Your Email" : "Enter Reset Code" : title,
1030
- subtitle: showVerificationStep ? "" : subtitle
1031
- }
1032
- ),
1016
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle: displaySubtitle }),
1033
1017
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1034
1018
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
1035
1019
  AuthResetPasswordVerificationStep,