@insforge/react 0.4.8 → 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.
@@ -136,34 +136,27 @@ function AuthPasswordStrengthIndicator({
136
136
  config
137
137
  }) {
138
138
  const requirements = createRequirements(config);
139
- 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(
140
- "div",
141
- {
142
- className: `if-passwordStrength-requirement ${req.test(password) ? "met" : "unmet"}`,
143
- children: [
144
- /* @__PURE__ */ jsxRuntime.jsx(
145
- "div",
146
- {
147
- style: {
148
- display: "flex",
149
- alignItems: "center",
150
- justifyContent: "center",
151
- width: "1rem",
152
- height: "1rem",
153
- borderRadius: "50%",
154
- border: "2px solid",
155
- borderColor: req.test(password) ? "transparent" : "#9ca3af",
156
- backgroundColor: req.test(password) ? "#059669" : "white",
157
- transition: "all 0.2s"
158
- },
159
- children: req.test(password) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { style: { width: "0.75rem", height: "0.75rem", color: "white" } })
160
- }
161
- ),
162
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: req.label })
163
- ]
164
- },
165
- req.label
166
- )) }) });
139
+ 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: [
140
+ /* @__PURE__ */ jsxRuntime.jsx(
141
+ "div",
142
+ {
143
+ style: {
144
+ display: "flex",
145
+ alignItems: "center",
146
+ justifyContent: "center",
147
+ width: "1rem",
148
+ height: "1rem",
149
+ borderRadius: "50%",
150
+ border: "2px solid",
151
+ borderColor: req.test(password) ? "transparent" : "#9ca3af",
152
+ backgroundColor: req.test(password) ? "#059669" : "white",
153
+ transition: "all 0.2s"
154
+ },
155
+ children: req.test(password) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { style: { width: "0.75rem", height: "0.75rem", color: "white" } })
156
+ }
157
+ ),
158
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: req.label })
159
+ ] }, req.label)) }) });
167
160
  }
168
161
  function createRequirements(config) {
169
162
  const requirements = [];
@@ -231,11 +224,12 @@ function AuthPasswordField({
231
224
  onFocus,
232
225
  ...props
233
226
  }) {
227
+ const [searchParams] = reactRouterDom.useSearchParams();
234
228
  const [showPassword, setShowPassword] = react.useState(false);
235
229
  const [showStrength, setShowStrength] = react.useState(false);
236
230
  const resolvedForgotPasswordHref = react.useMemo(
237
- () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
238
- [forgotPasswordLink]
231
+ () => forgotPasswordLink ? resolveAuthUrl(forgotPasswordLink.href, searchParams) : void 0,
232
+ [forgotPasswordLink, searchParams]
239
233
  );
240
234
  const handleFocus = (e) => {
241
235
  if (showStrengthIndicator) {
@@ -642,29 +636,20 @@ function AuthVerificationCodeInput({
642
636
  }
643
637
  function AuthEmailVerificationStep({
644
638
  email,
645
- method = "code",
646
- onVerifyCode
639
+ method,
640
+ onVerifyCode,
641
+ emailSent = false
647
642
  }) {
648
643
  const { sendVerificationEmail } = useInsforge();
649
644
  const [resendDisabled, setResendDisabled] = react.useState(true);
650
- const [resendCountdown, setResendCountdown] = react.useState(60);
645
+ const [resendCountdown, setResendCountdown] = react.useState(emailSent ? 60 : 0);
651
646
  const [isSending, setIsSending] = react.useState(false);
652
647
  const [verificationCode, setVerificationCode] = react.useState("");
653
648
  const [isVerifying, setIsVerifying] = react.useState(false);
654
649
  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
+ 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.";
656
651
  react.useEffect(() => {
657
- const sendInitialEmail = async () => {
658
- try {
659
- await sendVerificationEmail(email);
660
- } catch (error) {
661
- console.error("Failed to send verification email:", error);
662
- }
663
- };
664
- void sendInitialEmail();
665
- }, [email, sendVerificationEmail]);
666
- react.useEffect(() => {
667
- if (resendCountdown > 0) {
652
+ if (emailSent && resendCountdown > 0) {
668
653
  const timer = setInterval(() => {
669
654
  setResendCountdown((prev) => {
670
655
  if (prev <= 1) {
@@ -676,7 +661,7 @@ function AuthEmailVerificationStep({
676
661
  }, 1e3);
677
662
  return () => clearInterval(timer);
678
663
  }
679
- }, [resendCountdown]);
664
+ }, [emailSent, resendCountdown]);
680
665
  const handleResend = async () => {
681
666
  setResendDisabled(true);
682
667
  setResendCountdown(60);
@@ -863,7 +848,6 @@ function SignInForm({
863
848
  error,
864
849
  loading = false,
865
850
  oauthLoading = null,
866
- availableProviders = [],
867
851
  onOAuthClick,
868
852
  authConfig,
869
853
  title = "Welcome Back",
@@ -886,7 +870,15 @@ function SignInForm({
886
870
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
887
871
  /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
888
872
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
889
- showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
873
+ showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
874
+ AuthEmailVerificationStep,
875
+ {
876
+ email,
877
+ method: authConfig.verifyEmailMethod,
878
+ onVerifyCode,
879
+ emailSent: false
880
+ }
881
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
890
882
  /* @__PURE__ */ jsxRuntime.jsx(
891
883
  AuthFormField,
892
884
  {
@@ -921,12 +913,12 @@ function SignInForm({
921
913
  ] }),
922
914
  !showVerificationStep && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
923
915
  /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signUpText, linkText: signUpLinkText, href: signUpUrl }),
924
- availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
916
+ authConfig.oAuthProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
925
917
  /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
926
918
  /* @__PURE__ */ jsxRuntime.jsx(
927
919
  AuthOAuthProviders,
928
920
  {
929
- providers: availableProviders,
921
+ providers: authConfig.oAuthProviders,
930
922
  onClick: onOAuthClick,
931
923
  disabled: loading || oauthLoading !== null,
932
924
  loading: oauthLoading
@@ -1001,7 +993,15 @@ function SignIn({ onError, ...uiProps }) {
1001
993
  }
1002
994
  }
1003
995
  function handleOAuth(provider) {
1004
- loginWithOAuth(provider, redirectUrl || "");
996
+ try {
997
+ loginWithOAuth(provider, redirectUrl || "");
998
+ } catch (err) {
999
+ const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
1000
+ setError(errorMessage);
1001
+ if (onError) {
1002
+ onError(new Error(errorMessage));
1003
+ }
1004
+ }
1005
1005
  }
1006
1006
  if (!authConfig) {
1007
1007
  return null;
@@ -1017,7 +1017,6 @@ function SignIn({ onError, ...uiProps }) {
1017
1017
  error,
1018
1018
  loading,
1019
1019
  oauthLoading,
1020
- availableProviders: authConfig?.oAuthProviders || [],
1021
1020
  onOAuthClick: handleOAuth,
1022
1021
  authConfig,
1023
1022
  showVerificationStep: step === "awaiting-verification",
@@ -1035,7 +1034,6 @@ function SignUpForm({
1035
1034
  error,
1036
1035
  loading = false,
1037
1036
  oauthLoading = null,
1038
- availableProviders = [],
1039
1037
  onOAuthClick,
1040
1038
  authConfig,
1041
1039
  title = "Get Started",
@@ -1056,7 +1054,15 @@ function SignUpForm({
1056
1054
  return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { children: [
1057
1055
  /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1058
1056
  /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1059
- showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(AuthEmailVerificationStep, { email, onVerifyCode }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
1057
+ showVerificationStep ? /* @__PURE__ */ jsxRuntime.jsx(
1058
+ AuthEmailVerificationStep,
1059
+ {
1060
+ email,
1061
+ method: authConfig.verifyEmailMethod,
1062
+ onVerifyCode,
1063
+ emailSent: true
1064
+ }
1065
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, noValidate: true, className: "if-form if-internal-fm9k2p", children: [
1060
1066
  /* @__PURE__ */ jsxRuntime.jsx(
1061
1067
  AuthFormField,
1062
1068
  {
@@ -1079,7 +1085,6 @@ function SignUpForm({
1079
1085
  value: password,
1080
1086
  onChange: (e) => onPasswordChange(e.target.value),
1081
1087
  required: true,
1082
- minLength: authConfig.passwordMinLength,
1083
1088
  autoComplete: "new-password",
1084
1089
  showStrengthIndicator: true,
1085
1090
  authConfig
@@ -1089,12 +1094,12 @@ function SignUpForm({
1089
1094
  ] }),
1090
1095
  !showVerificationStep && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1091
1096
  /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signInText, linkText: signInLinkText, href: signInUrl }),
1092
- availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1097
+ authConfig.oAuthProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1093
1098
  /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
1094
1099
  /* @__PURE__ */ jsxRuntime.jsx(
1095
1100
  AuthOAuthProviders,
1096
1101
  {
1097
- providers: availableProviders,
1102
+ providers: authConfig.oAuthProviders,
1098
1103
  onClick: onOAuthClick,
1099
1104
  disabled: loading || oauthLoading !== null,
1100
1105
  loading: oauthLoading
@@ -1222,7 +1227,15 @@ function SignUp({ onError, ...uiProps }) {
1222
1227
  }
1223
1228
  }
1224
1229
  function handleOAuth(provider) {
1225
- loginWithOAuth(provider, redirectUrl || "");
1230
+ try {
1231
+ loginWithOAuth(provider, redirectUrl || "");
1232
+ } catch (err) {
1233
+ const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
1234
+ setError(errorMessage);
1235
+ if (onError) {
1236
+ onError(new Error(errorMessage));
1237
+ }
1238
+ }
1226
1239
  }
1227
1240
  if (!authConfig) {
1228
1241
  return null;
@@ -1238,7 +1251,6 @@ function SignUp({ onError, ...uiProps }) {
1238
1251
  error,
1239
1252
  loading,
1240
1253
  oauthLoading,
1241
- availableProviders: authConfig?.oAuthProviders || [],
1242
1254
  onOAuthClick: handleOAuth,
1243
1255
  authConfig,
1244
1256
  showVerificationStep: step === "awaiting-verification",