@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/atoms.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { AlertTriangle, Check, EyeOff, Eye, Loader2, CircleCheck } from 'lucide-react';
3
- import { createContext, useState, useRef, useEffect, useCallback, useContext } from 'react';
3
+ import { createContext, useState, useMemo, useRef, useEffect, useCallback, useContext } from 'react';
4
4
  import { useSearchParams } from 'react-router-dom';
5
5
  import '@insforge/sdk';
6
6
 
@@ -169,6 +169,28 @@ function createRequirements(config) {
169
169
  }
170
170
  return requirements;
171
171
  }
172
+
173
+ // src/lib/path-utils.ts
174
+ function resolveAuthPath(targetPath) {
175
+ if (typeof window === "undefined") {
176
+ return targetPath;
177
+ }
178
+ const currentPath = window.location.pathname;
179
+ if (currentPath.startsWith("/auth/")) {
180
+ if (targetPath.startsWith("/auth/")) {
181
+ return targetPath;
182
+ }
183
+ return `/auth${targetPath}`;
184
+ }
185
+ return targetPath;
186
+ }
187
+ function resolveAuthUrl(targetPath, searchParams) {
188
+ const resolvedPath = resolveAuthPath(targetPath);
189
+ if (!searchParams || searchParams.toString() === "") {
190
+ return resolvedPath;
191
+ }
192
+ return `${resolvedPath}?${searchParams.toString()}`;
193
+ }
172
194
  function AuthPasswordField({
173
195
  label,
174
196
  id,
@@ -181,6 +203,10 @@ function AuthPasswordField({
181
203
  }) {
182
204
  const [showPassword, setShowPassword] = useState(false);
183
205
  const [showStrength, setShowStrength] = useState(false);
206
+ const resolvedForgotPasswordHref = useMemo(
207
+ () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
208
+ [forgotPasswordLink]
209
+ );
184
210
  const handleFocus = (e) => {
185
211
  if (showStrengthIndicator) {
186
212
  setShowStrength(true);
@@ -190,7 +216,7 @@ function AuthPasswordField({
190
216
  return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
191
217
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
192
218
  /* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
193
- forgotPasswordLink && /* @__PURE__ */ jsx("a", { href: forgotPasswordLink.href, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
219
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
194
220
  ] }),
195
221
  /* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
196
222
  /* @__PURE__ */ jsx(
@@ -243,19 +269,7 @@ function AuthSubmitButton({
243
269
  }
244
270
  function AuthLink({ text, linkText, href }) {
245
271
  const [searchParams] = useSearchParams();
246
- const currentSearch = searchParams.toString();
247
- const finalHref = (() => {
248
- if (!currentSearch) {
249
- return href;
250
- }
251
- try {
252
- const url = new URL(href, window.location.origin);
253
- url.search = currentSearch;
254
- return url.pathname + url.search;
255
- } catch {
256
- return href;
257
- }
258
- })();
272
+ const finalHref = resolveAuthUrl(href, searchParams);
259
273
  return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
260
274
  text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
261
275
  text && " ",
@@ -529,7 +543,6 @@ function AuthOAuthProviders({
529
543
  function AuthVerificationCodeInput({
530
544
  length = 6,
531
545
  value,
532
- email,
533
546
  onChange,
534
547
  disabled = false,
535
548
  onComplete
@@ -577,33 +590,25 @@ function AuthVerificationCodeInput({
577
590
  }
578
591
  }
579
592
  };
580
- return /* @__PURE__ */ jsxs("div", { className: "if-verificationCode if-internal-vc8m4p", children: [
581
- /* @__PURE__ */ jsxs("p", { className: "if-verificationCode-description", children: [
582
- "We've sent a verification code to your inbox at",
583
- " ",
584
- /* @__PURE__ */ jsx("span", { className: "if-verificationCode-email", children: email }),
585
- ". Enter it below to proceed."
586
- ] }),
587
- /* @__PURE__ */ jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsx(
588
- "input",
589
- {
590
- ref: (el) => {
591
- inputRefs.current[index] = el;
592
- },
593
- type: "text",
594
- inputMode: "numeric",
595
- maxLength: 1,
596
- value: value[index] || "",
597
- onChange: (e) => handleChange(index, e.target.value),
598
- onKeyDown: (e) => handleKeyDown(index, e),
599
- onPaste: handlePaste,
600
- disabled,
601
- className: "if-verificationCode-input",
602
- autoComplete: "one-time-code"
593
+ return /* @__PURE__ */ jsx("div", { className: "if-verificationCode-inputContainer", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsx(
594
+ "input",
595
+ {
596
+ ref: (el) => {
597
+ inputRefs.current[index] = el;
603
598
  },
604
- index
605
- )) })
606
- ] });
599
+ type: "text",
600
+ inputMode: "numeric",
601
+ maxLength: 1,
602
+ value: value[index] || "",
603
+ onChange: (e) => handleChange(index, e.target.value),
604
+ onKeyDown: (e) => handleKeyDown(index, e),
605
+ onPaste: handlePaste,
606
+ disabled,
607
+ className: "if-verificationCode-input",
608
+ autoComplete: "one-time-code"
609
+ },
610
+ index
611
+ )) });
607
612
  }
608
613
  var InsforgeContext = createContext(void 0);
609
614
  function useInsforge() {
@@ -624,7 +629,8 @@ function AuthEmailVerificationStep({
624
629
  const [isSending, setIsSending] = useState(false);
625
630
  const [verificationCode, setVerificationCode] = useState("");
626
631
  const [isVerifying, setIsVerifying] = useState(false);
627
- 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.";
632
+ const isLinkMethod = method === "link";
633
+ 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.";
628
634
  useEffect(() => {
629
635
  const sendInitialEmail = async () => {
630
636
  try {
@@ -674,23 +680,29 @@ function AuthEmailVerificationStep({
674
680
  setVerificationCode("");
675
681
  }
676
682
  };
677
- const displayDescription = defaultDescription;
678
- const isLinkMethod = method === "link";
679
683
  return /* @__PURE__ */ jsxs("div", { className: "if-verificationStep", children: [
680
- /* @__PURE__ */ jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxs("span", { children: [
681
- part,
682
- index < array.length - 1 && /* @__PURE__ */ jsx("span", { className: "if-verificationCode-email", children: email })
683
- ] }, index)) }),
684
+ isLinkMethod && /* @__PURE__ */ jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
685
+ /* @__PURE__ */ jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Verify Your Email" }),
686
+ /* @__PURE__ */ jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxs("span", { children: [
687
+ part,
688
+ index < array.length - 1 && /* @__PURE__ */ jsx("span", { className: "if-verificationLink-email", children: email })
689
+ ] }, index)) })
690
+ ] }),
684
691
  !isLinkMethod && /* @__PURE__ */ jsxs("div", { className: "if-verificationStep-codeContainer", children: [
685
- /* @__PURE__ */ jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsx(
686
- AuthVerificationCodeInput,
687
- {
688
- value: verificationCode,
689
- onChange: setVerificationCode,
690
- email,
691
- disabled: isVerifying
692
- }
693
- ) }),
692
+ /* @__PURE__ */ jsxs("div", { className: "if-verificationStep-codeInputWrapper", children: [
693
+ /* @__PURE__ */ jsx("p", { className: "if-verificationStep-codeDescription", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxs("span", { children: [
694
+ part,
695
+ index < array.length - 1 && /* @__PURE__ */ jsx("span", { className: "if-verificationCode-email", children: email })
696
+ ] }, index)) }),
697
+ /* @__PURE__ */ jsx(
698
+ AuthVerificationCodeInput,
699
+ {
700
+ value: verificationCode,
701
+ onChange: setVerificationCode,
702
+ disabled: isVerifying
703
+ }
704
+ )
705
+ ] }),
694
706
  /* @__PURE__ */ jsx(
695
707
  AuthSubmitButton,
696
708
  {
@@ -700,7 +712,7 @@ function AuthEmailVerificationStep({
700
712
  onClick: () => {
701
713
  void handleSubmit();
702
714
  },
703
- children: isVerifying ? "Verifying..." : "Verify Code"
715
+ children: isVerifying ? "Verifying..." : "Continue"
704
716
  }
705
717
  )
706
718
  ] }),
@@ -732,6 +744,8 @@ function AuthResetPasswordVerificationStep({
732
744
  const [isSending, setIsSending] = useState(false);
733
745
  const [verificationCode, setVerificationCode] = useState("");
734
746
  const [isVerifying, setIsVerifying] = useState(false);
747
+ const isLinkMethod = method === "link";
748
+ 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.";
735
749
  useEffect(() => {
736
750
  if (resendCountdown > 0) {
737
751
  const timer = setInterval(() => {
@@ -771,17 +785,20 @@ function AuthResetPasswordVerificationStep({
771
785
  setVerificationCode("");
772
786
  }
773
787
  };
774
- const isLinkMethod = method === "link";
775
- 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.`;
776
788
  return /* @__PURE__ */ jsxs("div", { className: "if-verificationStep", children: [
777
- /* @__PURE__ */ jsx("p", { className: "if-verificationStep-description", children: description }),
789
+ isLinkMethod && /* @__PURE__ */ jsxs("div", { className: "if-verificationStep-descriptionContainer", children: [
790
+ /* @__PURE__ */ jsx("p", { className: "if-verificationStep-descriptionTitle", children: "Check Your Email" }),
791
+ /* @__PURE__ */ jsx("p", { className: "if-verificationStep-description", children: displayDescription.split("{email}").map((part, index, array) => /* @__PURE__ */ jsxs("span", { children: [
792
+ part,
793
+ index < array.length - 1 && /* @__PURE__ */ jsx("span", { className: "if-verificationLink-email", children: email })
794
+ ] }, index)) })
795
+ ] }),
778
796
  !isLinkMethod && /* @__PURE__ */ jsxs("div", { className: "if-verificationStep-codeContainer", children: [
779
797
  /* @__PURE__ */ jsx("div", { className: "if-verificationStep-codeInputWrapper", children: /* @__PURE__ */ jsx(
780
798
  AuthVerificationCodeInput,
781
799
  {
782
800
  value: verificationCode,
783
801
  onChange: setVerificationCode,
784
- email,
785
802
  disabled: isVerifying
786
803
  }
787
804
  ) }),