@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.
@@ -199,6 +199,28 @@ function createRequirements(config) {
199
199
  }
200
200
  return requirements;
201
201
  }
202
+
203
+ // src/lib/path-utils.ts
204
+ function resolveAuthPath(targetPath) {
205
+ if (typeof window === "undefined") {
206
+ return targetPath;
207
+ }
208
+ const currentPath = window.location.pathname;
209
+ if (currentPath.startsWith("/auth/")) {
210
+ if (targetPath.startsWith("/auth/")) {
211
+ return targetPath;
212
+ }
213
+ return `/auth${targetPath}`;
214
+ }
215
+ return targetPath;
216
+ }
217
+ function resolveAuthUrl(targetPath, searchParams) {
218
+ const resolvedPath = resolveAuthPath(targetPath);
219
+ if (!searchParams || searchParams.toString() === "") {
220
+ return resolvedPath;
221
+ }
222
+ return `${resolvedPath}?${searchParams.toString()}`;
223
+ }
202
224
  function AuthPasswordField({
203
225
  label,
204
226
  id,
@@ -211,6 +233,10 @@ function AuthPasswordField({
211
233
  }) {
212
234
  const [showPassword, setShowPassword] = react.useState(false);
213
235
  const [showStrength, setShowStrength] = react.useState(false);
236
+ const resolvedForgotPasswordHref = react.useMemo(
237
+ () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
238
+ [forgotPasswordLink]
239
+ );
214
240
  const handleFocus = (e) => {
215
241
  if (showStrengthIndicator) {
216
242
  setShowStrength(true);
@@ -220,7 +246,7 @@ function AuthPasswordField({
220
246
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
221
247
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-labelRow", children: [
222
248
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
223
- forgotPasswordLink && /* @__PURE__ */ jsxRuntime.jsx("a", { href: forgotPasswordLink.href, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
249
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsxRuntime.jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
224
250
  ] }),
225
251
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-inputWrapper", children: [
226
252
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -273,19 +299,7 @@ function AuthSubmitButton({
273
299
  }
274
300
  function AuthLink({ text, linkText, href }) {
275
301
  const [searchParams] = reactRouterDom.useSearchParams();
276
- const currentSearch = searchParams.toString();
277
- const finalHref = (() => {
278
- if (!currentSearch) {
279
- return href;
280
- }
281
- try {
282
- const url = new URL(href, window.location.origin);
283
- url.search = currentSearch;
284
- return url.pathname + url.search;
285
- } catch {
286
- return href;
287
- }
288
- })();
302
+ const finalHref = resolveAuthUrl(href, searchParams);
289
303
  return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
290
304
  text && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-authLink-text", children: text }),
291
305
  text && " ",
@@ -559,7 +573,6 @@ function AuthOAuthProviders({
559
573
  function AuthVerificationCodeInput({
560
574
  length = 6,
561
575
  value,
562
- email,
563
576
  onChange,
564
577
  disabled = false,
565
578
  onComplete
@@ -607,33 +620,25 @@ function AuthVerificationCodeInput({
607
620
  }
608
621
  }
609
622
  };
610
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationCode if-internal-vc8m4p", children: [
611
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-verificationCode-description", children: [
612
- "We've sent a verification code to your inbox at",
613
- " ",
614
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email }),
615
- ". Enter it below to proceed."
616
- ] }),
617
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
618
- "input",
619
- {
620
- ref: (el) => {
621
- inputRefs.current[index] = el;
622
- },
623
- type: "text",
624
- inputMode: "numeric",
625
- maxLength: 1,
626
- value: value[index] || "",
627
- onChange: (e) => handleChange(index, e.target.value),
628
- onKeyDown: (e) => handleKeyDown(index, e),
629
- onPaste: handlePaste,
630
- disabled,
631
- className: "if-verificationCode-input",
632
- autoComplete: "one-time-code"
623
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
624
+ "input",
625
+ {
626
+ ref: (el) => {
627
+ inputRefs.current[index] = el;
633
628
  },
634
- index
635
- )) })
636
- ] });
629
+ type: "text",
630
+ inputMode: "numeric",
631
+ maxLength: 1,
632
+ value: value[index] || "",
633
+ onChange: (e) => handleChange(index, e.target.value),
634
+ onKeyDown: (e) => handleKeyDown(index, e),
635
+ onPaste: handlePaste,
636
+ disabled,
637
+ className: "if-verificationCode-input",
638
+ autoComplete: "one-time-code"
639
+ },
640
+ index
641
+ )) });
637
642
  }
638
643
  function AuthEmailVerificationStep({
639
644
  email,
@@ -646,7 +651,8 @@ function AuthEmailVerificationStep({
646
651
  const [isSending, setIsSending] = react.useState(false);
647
652
  const [verificationCode, setVerificationCode] = react.useState("");
648
653
  const [isVerifying, setIsVerifying] = react.useState(false);
649
- 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.";
654
+ const isLinkMethod = method === "link";
655
+ 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.";
650
656
  react.useEffect(() => {
651
657
  const sendInitialEmail = async () => {
652
658
  try {
@@ -696,23 +702,29 @@ function AuthEmailVerificationStep({
696
702
  setVerificationCode("");
697
703
  }
698
704
  };
699
- const displayDescription = defaultDescription;
700
- const isLinkMethod = method === "link";
701
705
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
702
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
703
- part,
704
- index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
705
- ] }, index)) }),
706
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
707
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Verify Your Email" }),
708
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
709
+ part,
710
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
711
+ ] }, index)) })
712
+ ] }),
706
713
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
707
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
708
- AuthVerificationCodeInput,
709
- {
710
- value: verificationCode,
711
- onChange: setVerificationCode,
712
- email,
713
- disabled: isVerifying
714
- }
715
- ) }),
714
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeInputWrapper", children: [
715
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-codeDescription", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
716
+ part,
717
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationCode-email", children: email })
718
+ ] }, index)) }),
719
+ /* @__PURE__ */ jsxRuntime.jsx(
720
+ AuthVerificationCodeInput,
721
+ {
722
+ value: verificationCode,
723
+ onChange: setVerificationCode,
724
+ disabled: isVerifying
725
+ }
726
+ )
727
+ ] }),
716
728
  /* @__PURE__ */ jsxRuntime.jsx(
717
729
  AuthSubmitButton,
718
730
  {
@@ -722,7 +734,7 @@ function AuthEmailVerificationStep({
722
734
  onClick: () => {
723
735
  void handleSubmit();
724
736
  },
725
- children: isVerifying ? "Verifying..." : "Verify Code"
737
+ children: isVerifying ? "Verifying..." : "Continue"
726
738
  }
727
739
  )
728
740
  ] }),
@@ -754,6 +766,8 @@ function AuthResetPasswordVerificationStep({
754
766
  const [isSending, setIsSending] = react.useState(false);
755
767
  const [verificationCode, setVerificationCode] = react.useState("");
756
768
  const [isVerifying, setIsVerifying] = react.useState(false);
769
+ const isLinkMethod = method === "link";
770
+ 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.";
757
771
  react.useEffect(() => {
758
772
  if (resendCountdown > 0) {
759
773
  const timer = setInterval(() => {
@@ -793,17 +807,20 @@ function AuthResetPasswordVerificationStep({
793
807
  setVerificationCode("");
794
808
  }
795
809
  };
796
- const isLinkMethod = method === "link";
797
- 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.`;
798
810
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep", children: [
799
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: description }),
811
+ isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
812
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Check Your Email" }),
813
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
814
+ part,
815
+ index < array.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-verificationLink-email", children: email })
816
+ ] }, index)) })
817
+ ] }),
800
818
  !isLinkMethod && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-verificationStep-codeContainer", children: [
801
819
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
802
820
  AuthVerificationCodeInput,
803
821
  {
804
822
  value: verificationCode,
805
823
  onChange: setVerificationCode,
806
- email,
807
824
  disabled: isVerifying
808
825
  }
809
826
  ) }),
@@ -856,7 +873,7 @@ function SignInForm({
856
873
  passwordLabel = "Password",
857
874
  passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
858
875
  forgotPasswordText = "Forget Password?",
859
- forgotPasswordUrl,
876
+ forgotPasswordUrl = "/forgot-password",
860
877
  submitButtonText = "Sign In",
861
878
  loadingButtonText = "Signing in...",
862
879
  signUpText = "Don't have an account?",
@@ -867,13 +884,7 @@ function SignInForm({
867
884
  onVerifyCode
868
885
  }) {
869
886
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
870
- /* @__PURE__ */ jsxRuntime.jsx(
871
- AuthHeader,
872
- {
873
- title: showVerificationStep ? "Verify Your Email" : title,
874
- subtitle: showVerificationStep ? "" : subtitle
875
- }
876
- ),
887
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
877
888
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
878
889
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
879
890
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -972,7 +983,7 @@ function SignIn({ onError, ...uiProps }) {
972
983
  async function handleVerifyCode(code) {
973
984
  setError("");
974
985
  try {
975
- const result = await verifyEmail(email, code);
986
+ const result = await verifyEmail(code, email);
976
987
  if (result?.error) {
977
988
  throw new Error(result.error.message || "Verification failed");
978
989
  }
@@ -1043,13 +1054,7 @@ function SignUpForm({
1043
1054
  onVerifyCode
1044
1055
  }) {
1045
1056
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
1046
- /* @__PURE__ */ jsxRuntime.jsx(
1047
- AuthHeader,
1048
- {
1049
- title: showVerificationStep ? "Verify Your Email" : title,
1050
- subtitle: showVerificationStep ? "" : subtitle
1051
- }
1052
- ),
1057
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1053
1058
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1054
1059
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
1055
1060
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1199,7 +1204,7 @@ function SignUp({ onError, ...uiProps }) {
1199
1204
  async function handleVerifyCode(code) {
1200
1205
  setError("");
1201
1206
  try {
1202
- const result = await verifyEmail(email, code);
1207
+ const result = await verifyEmail(code, email);
1203
1208
  if (result?.error) {
1204
1209
  throw new Error(result.error.message || "Verification failed");
1205
1210
  }
@@ -1249,10 +1254,10 @@ function ForgotPasswordForm({
1249
1254
  error,
1250
1255
  loading = false,
1251
1256
  title = "Forgot Password?",
1252
- subtitle = "Enter your email address and we'll send you a code to reset your password.",
1257
+ subtitle = "Enter your email address and we'll send you a {method} to reset your password.",
1253
1258
  emailLabel = "Email",
1254
1259
  emailPlaceholder = "example@email.com",
1255
- submitButtonText = "Send Reset Code",
1260
+ submitButtonText = "Reset Password",
1256
1261
  loadingButtonText = "Sending...",
1257
1262
  backToSignInText = "Remember your password?",
1258
1263
  backToSignInUrl = "/sign-in",
@@ -1261,14 +1266,9 @@ function ForgotPasswordForm({
1261
1266
  onVerifyCode,
1262
1267
  onResendEmail
1263
1268
  }) {
1269
+ const displaySubtitle = subtitle.replace("{method}", resetPasswordMethod);
1264
1270
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
1265
- /* @__PURE__ */ jsxRuntime.jsx(
1266
- AuthHeader,
1267
- {
1268
- title: showVerificationStep ? resetPasswordMethod === "link" ? "Check Your Email" : "Enter Reset Code" : title,
1269
- subtitle: showVerificationStep ? "" : subtitle
1270
- }
1271
- ),
1271
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle: displaySubtitle }),
1272
1272
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1273
1273
  showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
1274
1274
  AuthResetPasswordVerificationStep,
@@ -1495,12 +1495,9 @@ function ForgotPassword({ onError, ...uiProps }) {
1495
1495
  const result = await resetPassword(resetToken, newPassword);
1496
1496
  if (result?.message) {
1497
1497
  setSuccess(true);
1498
- const signInUrl = new URL("/sign-in", window.location.origin);
1499
- searchParams.forEach((value, key) => {
1500
- signInUrl.searchParams.set(key, value);
1501
- });
1498
+ const signInUrl = resolveAuthUrl("/sign-in", searchParams);
1502
1499
  setTimeout(() => {
1503
- window.location.href = signInUrl.toString();
1500
+ window.location.href = signInUrl;
1504
1501
  }, 2e3);
1505
1502
  } else {
1506
1503
  const errorMessage = "Failed to reset password";
@@ -1918,23 +1915,24 @@ function Protect({
1918
1915
  onRedirect
1919
1916
  }) {
1920
1917
  const { isSignedIn, isLoaded, user } = useInsforge();
1918
+ const resolvedRedirectTo = react.useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
1921
1919
  react.useEffect(() => {
1922
1920
  if (isLoaded && !isSignedIn) {
1923
1921
  if (onRedirect) {
1924
- onRedirect(redirectTo);
1922
+ onRedirect(resolvedRedirectTo);
1925
1923
  } else {
1926
- window.location.href = redirectTo;
1924
+ window.location.href = resolvedRedirectTo;
1927
1925
  }
1928
1926
  } else if (isLoaded && isSignedIn && condition && user) {
1929
1927
  if (!condition(user)) {
1930
1928
  if (onRedirect) {
1931
- onRedirect(redirectTo);
1929
+ onRedirect(resolvedRedirectTo);
1932
1930
  } else {
1933
- window.location.href = redirectTo;
1931
+ window.location.href = resolvedRedirectTo;
1934
1932
  }
1935
1933
  }
1936
1934
  }
1937
- }, [isLoaded, isSignedIn, redirectTo, condition, user, onRedirect]);
1935
+ }, [isLoaded, isSignedIn, resolvedRedirectTo, condition, user, onRedirect]);
1938
1936
  if (!isLoaded) {
1939
1937
  return fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "insforge-loading", children: "Loading..." });
1940
1938
  }