@better-auth-ui/heroui 1.6.15 → 1.6.16

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/index.js CHANGED
@@ -309,6 +309,10 @@ function Ze({ className: e, variant: t, ...n }) {
309
309
  type: "email",
310
310
  autoComplete: "email",
311
311
  isDisabled: p,
312
+ validate: (e) => {
313
+ if (!e) return o.auth.fieldRequired;
314
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) return o.auth.invalidEmail;
315
+ },
312
316
  children: [
313
317
  /* @__PURE__ */ Q(z, { children: o.auth.email }),
314
318
  /* @__PURE__ */ Q(L, {
@@ -408,6 +412,12 @@ function Qe({ className: e, variant: t, ...n }) {
408
412
  name: "password",
409
413
  autoComplete: "new-password",
410
414
  isDisabled: u,
415
+ validate: (e) => {
416
+ if (!e) return o.auth.fieldRequired;
417
+ let t = a?.minPasswordLength, n = a?.maxPasswordLength;
418
+ if (t && e.length < t) return o.auth.tooShort.replace("{{min}}", String(t));
419
+ if (n && e.length > n) return o.auth.tooLong.replace("{{max}}", String(n));
420
+ },
411
421
  children: [
412
422
  /* @__PURE__ */ Q(z, { children: o.auth.password }),
413
423
  /* @__PURE__ */ $(R, {
@@ -439,6 +449,12 @@ function Qe({ className: e, variant: t, ...n }) {
439
449
  name: "confirmPassword",
440
450
  autoComplete: "new-password",
441
451
  isDisabled: u,
452
+ validate: (e) => {
453
+ if (!e) return o.auth.fieldRequired;
454
+ let t = a?.minPasswordLength, n = a?.maxPasswordLength;
455
+ if (t && e.length < t) return o.auth.tooShort.replace("{{min}}", String(t));
456
+ if (n && e.length > n) return o.auth.tooLong.replace("{{max}}", String(n));
457
+ },
442
458
  children: [
443
459
  /* @__PURE__ */ Q(z, { children: o.auth.confirmPassword }),
444
460
  /* @__PURE__ */ $(R, {
@@ -543,6 +559,10 @@ function $e({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
543
559
  type: "email",
544
560
  autoComplete: "email",
545
561
  isDisabled: w,
562
+ validate: (e) => {
563
+ if (!e) return f.auth.fieldRequired;
564
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) return f.auth.invalidEmail;
565
+ },
546
566
  children: [
547
567
  /* @__PURE__ */ Q(z, { children: f.auth.email }),
548
568
  /* @__PURE__ */ Q(L, {
@@ -562,6 +582,12 @@ function $e({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
562
582
  isDisabled: w,
563
583
  value: x,
564
584
  onChange: S,
585
+ validate: (e) => {
586
+ if (!e) return f.auth.fieldRequired;
587
+ let t = d?.minPasswordLength, n = d?.maxPasswordLength;
588
+ if (t && e.length < t) return f.auth.tooShort.replace("{{min}}", String(t));
589
+ if (n && e.length > n) return f.auth.tooLong.replace("{{max}}", String(n));
590
+ },
565
591
  children: [
566
592
  /* @__PURE__ */ Q(z, { children: f.auth.password }),
567
593
  /* @__PURE__ */ Q(L, {
@@ -702,6 +728,9 @@ function tt({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
702
728
  type: "text",
703
729
  autoComplete: "name",
704
730
  isDisabled: E,
731
+ validate: (e) => {
732
+ if (!e) return p.auth.fieldRequired;
733
+ },
705
734
  children: [
706
735
  /* @__PURE__ */ Q(z, { children: p.auth.name }),
707
736
  /* @__PURE__ */ Q(L, {
@@ -717,6 +746,10 @@ function tt({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
717
746
  type: "email",
718
747
  autoComplete: "email",
719
748
  isDisabled: E,
749
+ validate: (e) => {
750
+ if (!e) return p.auth.fieldRequired;
751
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) return p.auth.invalidEmail;
752
+ },
720
753
  children: [
721
754
  /* @__PURE__ */ Q(z, { children: p.auth.email }),
722
755
  /* @__PURE__ */ Q(L, {
@@ -741,6 +774,12 @@ function tt({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
741
774
  isDisabled: E,
742
775
  value: S,
743
776
  onChange: te,
777
+ validate: (e) => {
778
+ if (!e) return p.auth.fieldRequired;
779
+ let t = f?.minPasswordLength, n = f?.maxPasswordLength;
780
+ if (t && e.length < t) return p.auth.tooShort.replace("{{min}}", String(t));
781
+ if (n && e.length > n) return p.auth.tooLong.replace("{{max}}", String(n));
782
+ },
744
783
  children: [
745
784
  /* @__PURE__ */ Q(z, { children: p.auth.password }),
746
785
  /* @__PURE__ */ $(R, {
@@ -774,6 +813,12 @@ function tt({ className: t, socialLayout: n, socialPosition: i = "bottom", varia
774
813
  isDisabled: E,
775
814
  value: ne,
776
815
  onChange: C,
816
+ validate: (e) => {
817
+ if (!e) return p.auth.fieldRequired;
818
+ let t = f?.minPasswordLength, n = f?.maxPasswordLength;
819
+ if (t && e.length < t) return p.auth.tooShort.replace("{{min}}", String(t));
820
+ if (n && e.length > n) return p.auth.tooLong.replace("{{max}}", String(n));
821
+ },
777
822
  children: [
778
823
  /* @__PURE__ */ Q(z, { children: p.auth.confirmPassword }),
779
824
  /* @__PURE__ */ $(R, {
package/dist/plugins.js CHANGED
@@ -687,18 +687,18 @@ function Vt(e) {
687
687
  return e.toLowerCase().replace(/[^a-z0-9]+/g, "-");
688
688
  }
689
689
  function Ht({ value: e, onChange: t, currentSlug: n, variant: r, ...i }) {
690
- let { authClient: a } = p(), { localization: o, checkSlug: s } = m($), { mutate: c, data: l, error: u, reset: d } = _(a), f = yt((e) => {
691
- !s || !e.trim() || e.trim() === n || c({ slug: e.trim() });
690
+ let { authClient: a, localization: o } = p(), { localization: s, checkSlug: c } = m($), { mutate: l, data: u, error: d, reset: f } = _(a), h = yt((e) => {
691
+ !c || !e.trim() || e.trim() === n || l({ slug: e.trim() });
692
692
  }, { wait: 500 });
693
693
  at(() => {
694
- s && (d(), f.maybeExecute(e));
694
+ c && (f(), h.maybeExecute(e));
695
695
  }, [
696
- s,
696
+ c,
697
697
  e,
698
- f.maybeExecute,
699
- d
698
+ h.maybeExecute,
699
+ f
700
700
  ]);
701
- let h = (e) => {
701
+ let g = (e) => {
702
702
  t(Vt(e));
703
703
  };
704
704
  return /* @__PURE__ */ Z(G, {
@@ -706,17 +706,20 @@ function Ht({ value: e, onChange: t, currentSlug: n, variant: r, ...i }) {
706
706
  name: "slug",
707
707
  ...i,
708
708
  value: e,
709
- onChange: h,
709
+ onChange: g,
710
+ validate: (e) => {
711
+ if (!e) return o.auth.fieldRequired;
712
+ },
710
713
  children: [
711
- /* @__PURE__ */ X(R, { children: o.slug }),
714
+ /* @__PURE__ */ X(R, { children: s.slug }),
712
715
  /* @__PURE__ */ Z(L, {
713
716
  variant: r,
714
717
  children: [/* @__PURE__ */ X(L.Input, {
715
- placeholder: o.slugPlaceholder,
718
+ placeholder: s.slugPlaceholder,
716
719
  required: !0
717
- }), s && !!e.trim() && e.trim() !== n && /* @__PURE__ */ X(L.Suffix, {
720
+ }), c && !!e.trim() && e.trim() !== n && /* @__PURE__ */ X(L.Suffix, {
718
721
  className: "px-2",
719
- children: l?.status ? /* @__PURE__ */ X(Ee, { className: "text-success" }) : u ? /* @__PURE__ */ X(O, { className: "text-danger" }) : /* @__PURE__ */ X(H, {
722
+ children: u?.status ? /* @__PURE__ */ X(Ee, { className: "text-success" }) : d ? /* @__PURE__ */ X(O, { className: "text-danger" }) : /* @__PURE__ */ X(H, {
720
723
  size: "sm",
721
724
  color: "current"
722
725
  })
@@ -763,6 +766,9 @@ function Ut({ isOpen: e, onOpenChange: t }) {
763
766
  isDisabled: u,
764
767
  value: a,
765
768
  onChange: o,
769
+ validate: (e) => {
770
+ if (!e) return r.auth.fieldRequired;
771
+ },
766
772
  children: [
767
773
  /* @__PURE__ */ X(R, { children: i.name }),
768
774
  /* @__PURE__ */ X(I, {
@@ -1308,6 +1314,10 @@ function on({ isOpen: e, onOpenChange: t }) {
1308
1314
  name: "email",
1309
1315
  type: "email",
1310
1316
  isDisabled: l,
1317
+ validate: (e) => {
1318
+ if (!e) return r.auth.fieldRequired;
1319
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) return r.auth.invalidEmail;
1320
+ },
1311
1321
  children: [
1312
1322
  /* @__PURE__ */ X(R, { children: r.auth.email }),
1313
1323
  /* @__PURE__ */ X(I, {
@@ -2639,7 +2649,7 @@ function Ln({ name: e, field: t, isPending: n, variant: r }) {
2639
2649
  function y(e) {
2640
2650
  d(e), _(), c && v.maybeExecute(e);
2641
2651
  }
2642
- let b = !!c && !!u.trim() && u.trim() !== l;
2652
+ let b = !!c && !!u.trim() && u.trim() !== l, { localization: x } = p();
2643
2653
  return /* @__PURE__ */ Z(G, {
2644
2654
  name: e,
2645
2655
  type: "text",
@@ -2650,6 +2660,11 @@ function Ln({ name: e, field: t, isPending: n, variant: r }) {
2650
2660
  isReadOnly: t.readOnly,
2651
2661
  value: u,
2652
2662
  onChange: y,
2663
+ validate: (e) => {
2664
+ if (!e) return t.required ? x.auth.fieldRequired : void 0;
2665
+ if (o && e.length < o) return x.auth.tooShort.replace("{{min}}", String(o));
2666
+ if (s && e.length > s) return x.auth.tooLong.replace("{{max}}", String(s));
2667
+ },
2653
2668
  children: [
2654
2669
  /* @__PURE__ */ X(R, { children: t.label }),
2655
2670
  /* @__PURE__ */ Z(L, {
@@ -2743,6 +2758,9 @@ function zn({ className: n, socialLayout: i, socialPosition: a = "bottom", varia
2743
2758
  type: "text",
2744
2759
  autoComplete: "username email",
2745
2760
  isDisabled: E,
2761
+ validate: (e) => {
2762
+ if (!e) return f.auth.fieldRequired;
2763
+ },
2746
2764
  children: [
2747
2765
  /* @__PURE__ */ X(R, { children: S.username }),
2748
2766
  /* @__PURE__ */ X(I, {
@@ -2762,6 +2780,12 @@ function zn({ className: n, socialLayout: i, socialPosition: a = "bottom", varia
2762
2780
  isDisabled: E,
2763
2781
  value: C,
2764
2782
  onChange: T,
2783
+ validate: (e) => {
2784
+ if (!e) return f.auth.fieldRequired;
2785
+ let t = d?.minPasswordLength, n = d?.maxPasswordLength;
2786
+ if (t && e.length < t) return f.auth.tooShort.replace("{{min}}", String(t));
2787
+ if (n && e.length > n) return f.auth.tooLong.replace("{{max}}", String(n));
2788
+ },
2765
2789
  children: [
2766
2790
  /* @__PURE__ */ X(R, { children: f.auth.password }),
2767
2791
  /* @__PURE__ */ X(I, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth-ui/heroui",
3
- "version": "1.6.15",
3
+ "version": "1.6.16",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -98,6 +98,11 @@ export function ForgotPassword({
98
98
  type="email"
99
99
  autoComplete="email"
100
100
  isDisabled={isPending}
101
+ validate={(value) => {
102
+ if (!value) return localization.auth.fieldRequired
103
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value))
104
+ return localization.auth.invalidEmail
105
+ }}
101
106
  >
102
107
  <Label>{localization.auth.email}</Label>
103
108
 
@@ -93,6 +93,9 @@ export function CreateOrganizationDialog({
93
93
  isDisabled={isCreating}
94
94
  value={name}
95
95
  onChange={setName}
96
+ validate={(value) => {
97
+ if (!value) return localization.auth.fieldRequired
98
+ }}
96
99
  >
97
100
  <Label>{organizationLocalization.name}</Label>
98
101
 
@@ -108,6 +108,11 @@ export function InviteMemberDialog({
108
108
  name="email"
109
109
  type="email"
110
110
  isDisabled={isInviting}
111
+ validate={(value) => {
112
+ if (!value) return localization.auth.fieldRequired
113
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value))
114
+ return localization.auth.invalidEmail
115
+ }}
111
116
  >
112
117
  <Label>{localization.auth.email}</Label>
113
118
 
@@ -47,7 +47,7 @@ export function SlugField({
47
47
  variant,
48
48
  ...props
49
49
  }: SlugFieldProps & TextFieldProps) {
50
- const { authClient } = useAuth()
50
+ const { authClient, localization: authLocalization } = useAuth()
51
51
  const { localization, checkSlug: checkSlugEnabled } =
52
52
  useAuthPlugin(organizationPlugin)
53
53
 
@@ -86,6 +86,9 @@ export function SlugField({
86
86
  {...props}
87
87
  value={value}
88
88
  onChange={handleChange}
89
+ validate={(val) => {
90
+ if (!val) return authLocalization.auth.fieldRequired
91
+ }}
89
92
  >
90
93
  <Label>{localization.slug}</Label>
91
94
 
@@ -111,6 +111,18 @@ export function ResetPassword({
111
111
  name="password"
112
112
  autoComplete="new-password"
113
113
  isDisabled={isPending}
114
+ validate={(value) => {
115
+ if (!value) return localization.auth.fieldRequired
116
+ const min = emailAndPassword?.minPasswordLength
117
+ const max = emailAndPassword?.maxPasswordLength
118
+ if (min && value.length < min)
119
+ return localization.auth.tooShort.replace(
120
+ "{{min}}",
121
+ String(min)
122
+ )
123
+ if (max && value.length > max)
124
+ return localization.auth.tooLong.replace("{{max}}", String(max))
125
+ }}
114
126
  >
115
127
  <Label>{localization.auth.password}</Label>
116
128
 
@@ -152,6 +164,21 @@ export function ResetPassword({
152
164
  name="confirmPassword"
153
165
  autoComplete="new-password"
154
166
  isDisabled={isPending}
167
+ validate={(value) => {
168
+ if (!value) return localization.auth.fieldRequired
169
+ const min = emailAndPassword?.minPasswordLength
170
+ const max = emailAndPassword?.maxPasswordLength
171
+ if (min && value.length < min)
172
+ return localization.auth.tooShort.replace(
173
+ "{{min}}",
174
+ String(min)
175
+ )
176
+ if (max && value.length > max)
177
+ return localization.auth.tooLong.replace(
178
+ "{{max}}",
179
+ String(max)
180
+ )
181
+ }}
155
182
  >
156
183
  <Label>{localization.auth.confirmPassword}</Label>
157
184
 
@@ -156,6 +156,11 @@ export function SignIn({
156
156
  type="email"
157
157
  autoComplete="email"
158
158
  isDisabled={isPending}
159
+ validate={(value) => {
160
+ if (!value) return localization.auth.fieldRequired
161
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value))
162
+ return localization.auth.invalidEmail
163
+ }}
159
164
  >
160
165
  <Label>{localization.auth.email}</Label>
161
166
 
@@ -177,6 +182,21 @@ export function SignIn({
177
182
  isDisabled={isPending}
178
183
  value={password}
179
184
  onChange={setPassword}
185
+ validate={(value) => {
186
+ if (!value) return localization.auth.fieldRequired
187
+ const min = emailAndPassword?.minPasswordLength
188
+ const max = emailAndPassword?.maxPasswordLength
189
+ if (min && value.length < min)
190
+ return localization.auth.tooShort.replace(
191
+ "{{min}}",
192
+ String(min)
193
+ )
194
+ if (max && value.length > max)
195
+ return localization.auth.tooLong.replace(
196
+ "{{max}}",
197
+ String(max)
198
+ )
199
+ }}
180
200
  >
181
201
  <Label>{localization.auth.password}</Label>
182
202
 
@@ -185,6 +185,9 @@ export function SignUp({
185
185
  type="text"
186
186
  autoComplete="name"
187
187
  isDisabled={isPending}
188
+ validate={(value) => {
189
+ if (!value) return localization.auth.fieldRequired
190
+ }}
188
191
  >
189
192
  <Label>{localization.auth.name}</Label>
190
193
 
@@ -203,6 +206,11 @@ export function SignUp({
203
206
  type="email"
204
207
  autoComplete="email"
205
208
  isDisabled={isPending}
209
+ validate={(value) => {
210
+ if (!value) return localization.auth.fieldRequired
211
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value))
212
+ return localization.auth.invalidEmail
213
+ }}
206
214
  >
207
215
  <Label>{localization.auth.email}</Label>
208
216
 
@@ -236,6 +244,21 @@ export function SignUp({
236
244
  isDisabled={isPending}
237
245
  value={password}
238
246
  onChange={setPassword}
247
+ validate={(value) => {
248
+ if (!value) return localization.auth.fieldRequired
249
+ const min = emailAndPassword?.minPasswordLength
250
+ const max = emailAndPassword?.maxPasswordLength
251
+ if (min && value.length < min)
252
+ return localization.auth.tooShort.replace(
253
+ "{{min}}",
254
+ String(min)
255
+ )
256
+ if (max && value.length > max)
257
+ return localization.auth.tooLong.replace(
258
+ "{{max}}",
259
+ String(max)
260
+ )
261
+ }}
239
262
  >
240
263
  <Label>{localization.auth.password}</Label>
241
264
 
@@ -279,6 +302,21 @@ export function SignUp({
279
302
  isDisabled={isPending}
280
303
  value={confirmPassword}
281
304
  onChange={setConfirmPassword}
305
+ validate={(value) => {
306
+ if (!value) return localization.auth.fieldRequired
307
+ const min = emailAndPassword?.minPasswordLength
308
+ const max = emailAndPassword?.maxPasswordLength
309
+ if (min && value.length < min)
310
+ return localization.auth.tooShort.replace(
311
+ "{{min}}",
312
+ String(min)
313
+ )
314
+ if (max && value.length > max)
315
+ return localization.auth.tooLong.replace(
316
+ "{{max}}",
317
+ String(max)
318
+ )
319
+ }}
282
320
  >
283
321
  <Label>{localization.auth.confirmPassword}</Label>
284
322
 
@@ -182,6 +182,9 @@ export function SignInUsername({
182
182
  type="text"
183
183
  autoComplete="username email"
184
184
  isDisabled={isPending}
185
+ validate={(value) => {
186
+ if (!value) return localization.auth.fieldRequired
187
+ }}
185
188
  >
186
189
  <Label>{usernameLocalization.username}</Label>
187
190
 
@@ -203,6 +206,21 @@ export function SignInUsername({
203
206
  isDisabled={isPending}
204
207
  value={password}
205
208
  onChange={setPassword}
209
+ validate={(value) => {
210
+ if (!value) return localization.auth.fieldRequired
211
+ const min = emailAndPassword?.minPasswordLength
212
+ const max = emailAndPassword?.maxPasswordLength
213
+ if (min && value.length < min)
214
+ return localization.auth.tooShort.replace(
215
+ "{{min}}",
216
+ String(min)
217
+ )
218
+ if (max && value.length > max)
219
+ return localization.auth.tooLong.replace(
220
+ "{{max}}",
221
+ String(max)
222
+ )
223
+ }}
206
224
  >
207
225
  <Label>{localization.auth.password}</Label>
208
226
 
@@ -76,6 +76,8 @@ export function UsernameField({
76
76
  const isCheckingAvailability =
77
77
  !!checkAvailability && !!value.trim() && value.trim() !== currentUsername
78
78
 
79
+ const { localization: authLocalization } = useAuth()
80
+
79
81
  return (
80
82
  <TextField
81
83
  name={name}
@@ -87,6 +89,22 @@ export function UsernameField({
87
89
  isReadOnly={field.readOnly}
88
90
  value={value}
89
91
  onChange={handleChange}
92
+ validate={(val) => {
93
+ if (!val) {
94
+ if (field.required) return authLocalization.auth.fieldRequired
95
+ return
96
+ }
97
+ if (minUsernameLength && val.length < minUsernameLength)
98
+ return authLocalization.auth.tooShort.replace(
99
+ "{{min}}",
100
+ String(minUsernameLength)
101
+ )
102
+ if (maxUsernameLength && val.length > maxUsernameLength)
103
+ return authLocalization.auth.tooLong.replace(
104
+ "{{max}}",
105
+ String(maxUsernameLength)
106
+ )
107
+ }}
90
108
  >
91
109
  <Label>{field.label}</Label>
92
110