@better-auth-ui/heroui 1.6.26 → 1.6.27

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.
@@ -8,9 +8,9 @@ export type VerifyEmailProps = {
8
8
  * that is rate-limited by a cooldown timer.
9
9
  *
10
10
  * The target email is read from `sessionStorage` (set when sign-up or sign-in
11
- * redirects here); if none is stored the user is redirected back to sign-in.
12
- * The resend button is disabled while a cooldown is active and shows the
13
- * remaining seconds.
11
+ * redirects here); the OpenEmail/Resend controls are only shown when an email
12
+ * is stored. The resend button is disabled while a cooldown is active and shows
13
+ * the remaining seconds.
14
14
  *
15
15
  * @param className - Additional CSS classes applied to the outer card container
16
16
  * @param variant - Variant to apply to the card
package/dist/index.js CHANGED
@@ -907,28 +907,19 @@ function st({ email: e, className: t }) {
907
907
  //#region src/components/auth/verify-email.tsx
908
908
  var ct = 60;
909
909
  function lt({ className: e, variant: t }) {
910
- let { authClient: n, basePaths: r, baseURL: i, localization: a, navigate: o, redirectTo: s, viewPaths: c } = h(), [l, u] = X(Fe() && sessionStorage.getItem("better-auth-ui.verify-email") || ""), [d, f] = X(ct);
910
+ let { authClient: n, basePaths: r, baseURL: i, localization: a, redirectTo: o, viewPaths: s } = h(), [c, l] = X(Fe() && sessionStorage.getItem("better-auth-ui.verify-email") || ""), [u, d] = X(ct);
911
911
  Y(() => {
912
- let e = sessionStorage.getItem("better-auth-ui.verify-email");
913
- if (!e) {
914
- o({ to: `${r.auth}/${c.auth.signIn}` });
915
- return;
916
- }
917
- u(e);
918
- }, [
919
- r.auth,
920
- o,
921
- c.auth.signIn
922
- ]), Y(() => {
923
- if (d <= 0) return;
912
+ l(sessionStorage.getItem("better-auth-ui.verify-email") ?? "");
913
+ }, []), Y(() => {
914
+ if (u <= 0 || !c) return;
924
915
  let e = setInterval(() => {
925
- f((e) => e > 0 ? e - 1 : 0);
916
+ d((e) => e > 0 ? e - 1 : 0);
926
917
  }, 1e3);
927
918
  return () => clearInterval(e);
928
- }, [d]);
929
- let { mutate: p, isPending: m } = ne(n, { onSuccess: () => {
930
- J.success(a.auth.verificationEmailSent), f(ct);
931
- } }), g = d > 0;
919
+ }, [u, c]);
920
+ let { mutate: f, isPending: p } = ne(n, { onSuccess: () => {
921
+ J.success(a.auth.verificationEmailSent), d(ct);
922
+ } }), m = u > 0;
932
923
  return /* @__PURE__ */ $(j, {
933
924
  className: q("w-full max-w-sm gap-4 md:p-6", e),
934
925
  variant: t,
@@ -942,21 +933,21 @@ function lt({ className: e, variant: t }) {
942
933
  children: [/* @__PURE__ */ Q(N, {
943
934
  className: "text-sm",
944
935
  children: a.auth.checkYourEmail
945
- }), /* @__PURE__ */ $("div", {
936
+ }), c && /* @__PURE__ */ $("div", {
946
937
  className: "flex flex-col gap-3",
947
- children: [/* @__PURE__ */ Q(st, { email: l }), /* @__PURE__ */ $(k, {
938
+ children: [/* @__PURE__ */ Q(st, { email: c }), /* @__PURE__ */ $(k, {
948
939
  className: "w-full",
949
940
  variant: "tertiary",
950
- isDisabled: !l || g || m,
951
- isPending: m,
952
- onPress: () => p({
953
- email: l,
954
- callbackURL: `${i}${s}`
941
+ isDisabled: !c || m || p,
942
+ isPending: p,
943
+ onPress: () => f({
944
+ email: c,
945
+ callbackURL: `${i}${o}`
955
946
  }),
956
- children: [m && /* @__PURE__ */ Q(W, {
947
+ children: [p && /* @__PURE__ */ Q(W, {
957
948
  color: "current",
958
949
  size: "sm"
959
- }), g ? a.auth.resendIn.replace("{{seconds}}", String(d)) : a.auth.resend]
950
+ }), m ? a.auth.resendIn.replace("{{seconds}}", String(u)) : a.auth.resend]
960
951
  })]
961
952
  })]
962
953
  }),
@@ -968,7 +959,7 @@ function lt({ className: e, variant: t }) {
968
959
  a.auth.alreadyVerifiedYourEmail,
969
960
  " ",
970
961
  /* @__PURE__ */ Q(V, {
971
- href: `${r.auth}/${c.auth.signIn}`,
962
+ href: `${r.auth}/${s.auth.signIn}`,
972
963
  className: "text-accent no-underline hover:underline decoration-accent-hover",
973
964
  children: a.auth.signIn
974
965
  })
package/dist/plugins.js CHANGED
@@ -2712,12 +2712,16 @@ function Fn({ className: n, socialLayout: i, socialPosition: a = "bottom", varia
2712
2712
  onError: (e, { email: t }) => {
2713
2713
  S(""), e.error?.code === "EMAIL_NOT_VERIFIED" && (sessionStorage.setItem("better-auth-ui.verify-email", t), _({ to: `${c.auth}/${g.auth.verifyEmail}` })), y();
2714
2714
  },
2715
- onSuccess: () => _({ to: f })
2715
+ onSuccess: () => {
2716
+ sessionStorage.removeItem("better-auth-ui.verify-email"), _({ to: f });
2717
+ }
2716
2718
  }), { mutate: te, isPending: ne } = ye(s, {
2717
- onError: () => {
2718
- S(""), y();
2719
+ onError: (e) => {
2720
+ S(""), e.error?.code === "EMAIL_NOT_VERIFIED" && (sessionStorage.removeItem("better-auth-ui.verify-email"), _({ to: `${c.auth}/${g.auth.verifyEmail}` })), y();
2719
2721
  },
2720
- onSuccess: () => _({ to: f })
2722
+ onSuccess: () => {
2723
+ sessionStorage.removeItem("better-auth-ui.verify-email"), _({ to: f });
2724
+ }
2721
2725
  }), re = (e) => {
2722
2726
  e.preventDefault();
2723
2727
  let t = new FormData(e.currentTarget), n = t.get("email"), r = t.get("rememberMe") === "on";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth-ui/heroui",
3
- "version": "1.6.26",
3
+ "version": "1.6.27",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -82,16 +82,31 @@ export function SignInUsername({
82
82
 
83
83
  resetFetchOptions()
84
84
  },
85
- onSuccess: () => navigate({ to: redirectTo })
85
+ onSuccess: () => {
86
+ sessionStorage.removeItem("better-auth-ui.verify-email")
87
+ navigate({ to: redirectTo })
88
+ }
86
89
  })
87
90
 
88
91
  const { mutate: signInUsername, isPending: isSignInUsernamePending } =
89
92
  useSignInUsername(authClient as UsernameAuthClient, {
90
- onError: () => {
93
+ onError: (error) => {
91
94
  setPassword("")
95
+
96
+ if (error.error?.code === "EMAIL_NOT_VERIFIED") {
97
+ sessionStorage.removeItem("better-auth-ui.verify-email")
98
+
99
+ navigate({
100
+ to: `${basePaths.auth}/${viewPaths.auth.verifyEmail}`
101
+ })
102
+ }
103
+
92
104
  resetFetchOptions()
93
105
  },
94
- onSuccess: () => navigate({ to: redirectTo })
106
+ onSuccess: () => {
107
+ sessionStorage.removeItem("better-auth-ui.verify-email")
108
+ navigate({ to: redirectTo })
109
+ }
95
110
  })
96
111
 
97
112
  const handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
@@ -27,9 +27,9 @@ const RESEND_COOLDOWN_SECONDS = 60
27
27
  * that is rate-limited by a cooldown timer.
28
28
  *
29
29
  * The target email is read from `sessionStorage` (set when sign-up or sign-in
30
- * redirects here); if none is stored the user is redirected back to sign-in.
31
- * The resend button is disabled while a cooldown is active and shows the
32
- * remaining seconds.
30
+ * redirects here); the OpenEmail/Resend controls are only shown when an email
31
+ * is stored. The resend button is disabled while a cooldown is active and shows
32
+ * the remaining seconds.
33
33
  *
34
34
  * @param className - Additional CSS classes applied to the outer card container
35
35
  * @param variant - Variant to apply to the card
@@ -41,7 +41,6 @@ export function VerifyEmail({ className, variant }: VerifyEmailProps) {
41
41
  basePaths,
42
42
  baseURL,
43
43
  localization,
44
- navigate,
45
44
  redirectTo,
46
45
  viewPaths
47
46
  } = useAuth()
@@ -53,25 +52,18 @@ export function VerifyEmail({ className, variant }: VerifyEmailProps) {
53
52
  const [cooldown, setCooldown] = useState(RESEND_COOLDOWN_SECONDS)
54
53
 
55
54
  useEffect(() => {
56
- const storedEmail = sessionStorage.getItem("better-auth-ui.verify-email")
57
-
58
- if (!storedEmail) {
59
- navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` })
60
- return
61
- }
62
-
63
- setEmail(storedEmail)
64
- }, [basePaths.auth, navigate, viewPaths.auth.signIn])
55
+ setEmail(sessionStorage.getItem("better-auth-ui.verify-email") ?? "")
56
+ }, [])
65
57
 
66
58
  useEffect(() => {
67
- if (cooldown <= 0) return
59
+ if (cooldown <= 0 || !email) return
68
60
 
69
61
  const interval = setInterval(() => {
70
62
  setCooldown((current) => (current > 0 ? current - 1 : 0))
71
63
  }, 1000)
72
64
 
73
65
  return () => clearInterval(interval)
74
- }, [cooldown])
66
+ }, [cooldown, email])
75
67
 
76
68
  const { mutate: sendVerificationEmail, isPending } = useSendVerificationEmail(
77
69
  authClient,
@@ -101,31 +93,33 @@ export function VerifyEmail({ className, variant }: VerifyEmailProps) {
101
93
  {localization.auth.checkYourEmail}
102
94
  </Description>
103
95
 
104
- <div className="flex flex-col gap-3">
105
- <OpenEmailButton email={email} />
106
-
107
- <Button
108
- className="w-full"
109
- variant="tertiary"
110
- isDisabled={!email || isCoolingDown || isPending}
111
- isPending={isPending}
112
- onPress={() =>
113
- sendVerificationEmail({
114
- email,
115
- callbackURL: `${baseURL}${redirectTo}`
116
- })
117
- }
118
- >
119
- {isPending && <Spinner color="current" size="sm" />}
120
-
121
- {isCoolingDown
122
- ? localization.auth.resendIn.replace(
123
- "{{seconds}}",
124
- String(cooldown)
125
- )
126
- : localization.auth.resend}
127
- </Button>
128
- </div>
96
+ {email && (
97
+ <div className="flex flex-col gap-3">
98
+ <OpenEmailButton email={email} />
99
+
100
+ <Button
101
+ className="w-full"
102
+ variant="tertiary"
103
+ isDisabled={!email || isCoolingDown || isPending}
104
+ isPending={isPending}
105
+ onPress={() =>
106
+ sendVerificationEmail({
107
+ email,
108
+ callbackURL: `${baseURL}${redirectTo}`
109
+ })
110
+ }
111
+ >
112
+ {isPending && <Spinner color="current" size="sm" />}
113
+
114
+ {isCoolingDown
115
+ ? localization.auth.resendIn.replace(
116
+ "{{seconds}}",
117
+ String(cooldown)
118
+ )
119
+ : localization.auth.resend}
120
+ </Button>
121
+ </div>
122
+ )}
129
123
  </Card.Content>
130
124
 
131
125
  <Card.Footer className="flex-col gap-3">