@insforge/react 0.4.6 → 0.4.8

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
@@ -171,6 +171,28 @@ function createRequirements(config) {
171
171
  }
172
172
  return requirements;
173
173
  }
174
+
175
+ // src/lib/path-utils.ts
176
+ function resolveAuthPath(targetPath) {
177
+ if (typeof window === "undefined") {
178
+ return targetPath;
179
+ }
180
+ const currentPath = window.location.pathname;
181
+ if (currentPath.startsWith("/auth/")) {
182
+ if (targetPath.startsWith("/auth/")) {
183
+ return targetPath;
184
+ }
185
+ return `/auth${targetPath}`;
186
+ }
187
+ return targetPath;
188
+ }
189
+ function resolveAuthUrl(targetPath, searchParams) {
190
+ const resolvedPath = resolveAuthPath(targetPath);
191
+ if (!searchParams || searchParams.toString() === "") {
192
+ return resolvedPath;
193
+ }
194
+ return `${resolvedPath}?${searchParams.toString()}`;
195
+ }
174
196
  function AuthPasswordField({
175
197
  label,
176
198
  id,
@@ -183,6 +205,10 @@ function AuthPasswordField({
183
205
  }) {
184
206
  const [showPassword, setShowPassword] = react.useState(false);
185
207
  const [showStrength, setShowStrength] = react.useState(false);
208
+ const resolvedForgotPasswordHref = react.useMemo(
209
+ () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
210
+ [forgotPasswordLink]
211
+ );
186
212
  const handleFocus = (e) => {
187
213
  if (showStrengthIndicator) {
188
214
  setShowStrength(true);
@@ -192,7 +218,7 @@ function AuthPasswordField({
192
218
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
193
219
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-labelRow", children: [
194
220
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
195
- forgotPasswordLink && /* @__PURE__ */ jsxRuntime.jsx("a", { href: forgotPasswordLink.href, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
221
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsxRuntime.jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
196
222
  ] }),
197
223
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-inputWrapper", children: [
198
224
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -245,19 +271,7 @@ function AuthSubmitButton({
245
271
  }
246
272
  function AuthLink({ text, linkText, href }) {
247
273
  const [searchParams] = reactRouterDom.useSearchParams();
248
- const currentSearch = searchParams.toString();
249
- const finalHref = (() => {
250
- if (!currentSearch) {
251
- return href;
252
- }
253
- try {
254
- const url = new URL(href, window.location.origin);
255
- url.search = currentSearch;
256
- return url.pathname + url.search;
257
- } catch {
258
- return href;
259
- }
260
- })();
274
+ const finalHref = resolveAuthUrl(href, searchParams);
261
275
  return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
262
276
  text && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-authLink-text", children: text }),
263
277
  text && " ",
@@ -531,7 +545,6 @@ function AuthOAuthProviders({
531
545
  function AuthVerificationCodeInput({
532
546
  length = 6,
533
547
  value,
534
- email,
535
548
  onChange,
536
549
  disabled = false,
537
550
  onComplete
@@ -579,33 +592,25 @@ function AuthVerificationCodeInput({
579
592
  }
580
593
  }
581
594
  };
582
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationCode if-internal-vc8m4p", children: [
583
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-verificationCode-description", children: [
584
- "We've sent a verification code to your inbox at",
585
- " ",
586
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email }),
587
- ". Enter it below to proceed."
588
- ] }),
589
- /* @__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;
594
- },
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"
595
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
596
+ "input",
597
+ {
598
+ ref: (el) => {
599
+ inputRefs.current[index] = el;
605
600
  },
606
- index
607
- )) })
608
- ] });
601
+ type: "text",
602
+ inputMode: "numeric",
603
+ maxLength: 1,
604
+ value: value[index] || "",
605
+ onChange: (e) => handleChange(index, e.target.value),
606
+ onKeyDown: (e) => handleKeyDown(index, e),
607
+ onPaste: handlePaste,
608
+ disabled,
609
+ className: "if-verificationCode-input",
610
+ autoComplete: "one-time-code"
611
+ },
612
+ index
613
+ )) });
609
614
  }
610
615
  var InsforgeContext = react.createContext(void 0);
611
616
  function useInsforge() {
@@ -626,7 +631,8 @@ function AuthEmailVerificationStep({
626
631
  const [isSending, setIsSending] = react.useState(false);
627
632
  const [verificationCode, setVerificationCode] = react.useState("");
628
633
  const [isVerifying, setIsVerifying] = react.useState(false);
629
- 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.";
634
+ const isLinkMethod = method === "link";
635
+ const displayDescription = isLinkMethod ? "We have 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.";
630
636
  react.useEffect(() => {
631
637
  const sendInitialEmail = async () => {
632
638
  try {
@@ -676,23 +682,29 @@ function AuthEmailVerificationStep({
676
682
  setVerificationCode("");
677
683
  }
678
684
  };
679
- const displayDescription = defaultDescription;
680
- const isLinkMethod = method === "link";
681
685
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
682
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
683
- part,
684
- index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
685
- ] }, index)) }),
686
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
687
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Verify Your Email" }),
688
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
689
+ part,
690
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
691
+ ] }, index)) })
692
+ ] }),
686
693
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
687
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
688
- AuthVerificationCodeInput,
689
- {
690
- value: verificationCode,
691
- onChange: setVerificationCode,
692
- email,
693
- disabled: isVerifying
694
- }
695
- ) }),
694
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeInputWrapper", children: [
695
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-codeDescription", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
696
+ part,
697
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
698
+ ] }, index)) }),
699
+ /* @__PURE__ */ jsxRuntime.jsx(
700
+ AuthVerificationCodeInput,
701
+ {
702
+ value: verificationCode,
703
+ onChange: setVerificationCode,
704
+ disabled: isVerifying
705
+ }
706
+ )
707
+ ] }),
696
708
  /* @__PURE__ */ jsxRuntime.jsx(
697
709
  AuthSubmitButton,
698
710
  {
@@ -702,7 +714,7 @@ function AuthEmailVerificationStep({
702
714
  onClick: () => {
703
715
  void handleSubmit();
704
716
  },
705
- children: isVerifying ? "Verifying..." : "Verify Code"
717
+ children: isVerifying ? "Verifying..." : "Continue"
706
718
  }
707
719
  )
708
720
  ] }),
@@ -734,6 +746,8 @@ function AuthResetPasswordVerificationStep({
734
746
  const [isSending, setIsSending] = react.useState(false);
735
747
  const [verificationCode, setVerificationCode] = react.useState("");
736
748
  const [isVerifying, setIsVerifying] = react.useState(false);
749
+ const isLinkMethod = method === "link";
750
+ 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.";
737
751
  react.useEffect(() => {
738
752
  if (resendCountdown > 0) {
739
753
  const timer = setInterval(() => {
@@ -773,17 +787,20 @@ function AuthResetPasswordVerificationStep({
773
787
  setVerificationCode("");
774
788
  }
775
789
  };
776
- const isLinkMethod = method === "link";
777
- 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.`;
778
790
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
779
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: description }),
791
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
792
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Check Your Email" }),
793
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
794
+ part,
795
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
796
+ ] }, index)) })
797
+ ] }),
780
798
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
781
799
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
782
800
  AuthVerificationCodeInput,
783
801
  {
784
802
  value: verificationCode,
785
803
  onChange: setVerificationCode,
786
- email,
787
804
  disabled: isVerifying
788
805
  }
789
806
  ) }),
@@ -836,7 +853,7 @@ function SignInForm({
836
853
  passwordLabel = "Password",
837
854
  passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
838
855
  forgotPasswordText = "Forget Password?",
839
- forgotPasswordUrl,
856
+ forgotPasswordUrl = "/forgot-password",
840
857
  submitButtonText = "Sign In",
841
858
  loadingButtonText = "Signing in...",
842
859
  signUpText = "Don't have an account?",
@@ -847,13 +864,7 @@ function SignInForm({
847
864
  onVerifyCode
848
865
  }) {
849
866
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
850
- /* @__PURE__ */ jsxRuntime.jsx(
851
- AuthHeader,
852
- {
853
- title: showVerificationStep ? "Verify Your Email" : title,
854
- subtitle: showVerificationStep ? "" : subtitle
855
- }
856
- ),
867
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
857
868
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
858
869
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
859
870
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -933,13 +944,7 @@ function SignUpForm({
933
944
  onVerifyCode
934
945
  }) {
935
946
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
936
- /* @__PURE__ */ jsxRuntime.jsx(
937
- AuthHeader,
938
- {
939
- title: showVerificationStep ? "Verify Your Email" : title,
940
- subtitle: showVerificationStep ? "" : subtitle
941
- }
942
- ),
947
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
943
948
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
944
949
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
945
950
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -996,10 +1001,10 @@ function ForgotPasswordForm({
996
1001
  error,
997
1002
  loading = false,
998
1003
  title = "Forgot Password?",
999
- subtitle = "Enter your email address and we'll send you a code to reset your password.",
1004
+ subtitle = "Enter your email address and we'll send you a {method} to reset your password.",
1000
1005
  emailLabel = "Email",
1001
1006
  emailPlaceholder = "example@email.com",
1002
- submitButtonText = "Send Reset Code",
1007
+ submitButtonText = "Reset Password",
1003
1008
  loadingButtonText = "Sending...",
1004
1009
  backToSignInText = "Remember your password?",
1005
1010
  backToSignInUrl = "/sign-in",
@@ -1008,14 +1013,9 @@ function ForgotPasswordForm({
1008
1013
  onVerifyCode,
1009
1014
  onResendEmail
1010
1015
  }) {
1016
+ const displaySubtitle = subtitle.replace("{method}", resetPasswordMethod);
1011
1017
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
1012
- /* @__PURE__ */ jsxRuntime.jsx(
1013
- AuthHeader,
1014
- {
1015
- title: showVerificationStep ? resetPasswordMethod === "link" ? "Check Your Email" : "Enter Reset Code" : title,
1016
- subtitle: showVerificationStep ? "" : subtitle
1017
- }
1018
- ),
1018
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle: displaySubtitle }),
1019
1019
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1020
1020
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
1021
1021
  AuthResetPasswordVerificationStep,