@better-auth-ui/heroui 1.6.0 → 1.6.2
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/components/auth/auth-provider.d.ts +1 -1
- package/dist/components/auth/auth-provider.js +15 -11
- package/dist/components/auth/auth.d.ts +3 -3
- package/dist/components/auth/auth.js +36 -41
- package/dist/components/auth/field-separator.d.ts +1 -1
- package/dist/components/auth/field-separator.js +17 -4
- package/dist/components/auth/forgot-password.d.ts +1 -1
- package/dist/components/auth/forgot-password.js +69 -27
- package/dist/components/auth/magic-link-button.d.ts +1 -1
- package/dist/components/auth/magic-link-button.js +15 -18
- package/dist/components/auth/magic-link.d.ts +2 -2
- package/dist/components/auth/magic-link.js +110 -42
- package/dist/components/auth/passkey-button.d.ts +4 -0
- package/dist/components/auth/passkey-button.js +24 -0
- package/dist/components/auth/provider-buttons.d.ts +1 -1
- package/dist/components/auth/provider-buttons.js +26 -33
- package/dist/components/auth/reset-password.d.ts +1 -1
- package/dist/components/auth/reset-password.js +146 -57
- package/dist/components/auth/sign-in.d.ts +2 -2
- package/dist/components/auth/sign-in.js +163 -63
- package/dist/components/auth/sign-out.js +26 -32
- package/dist/components/auth/sign-up.d.ts +2 -2
- package/dist/components/auth/sign-up.js +240 -70
- package/dist/components/email/email-changed-email.d.ts +2 -2
- package/dist/components/email/email-changed-email.js +29 -22
- package/dist/components/email/email-verification-email.d.ts +2 -2
- package/dist/components/email/email-verification-email.js +29 -22
- package/dist/components/email/magic-link-email.d.ts +2 -2
- package/dist/components/email/magic-link-email.js +29 -22
- package/dist/components/email/new-device-email.d.ts +2 -2
- package/dist/components/email/new-device-email.js +29 -22
- package/dist/components/email/otp-email.d.ts +2 -2
- package/dist/components/email/otp-email.js +28 -21
- package/dist/components/email/password-changed-email.d.ts +2 -2
- package/dist/components/email/password-changed-email.js +29 -22
- package/dist/components/email/reset-password-email.d.ts +2 -2
- package/dist/components/email/reset-password-email.js +29 -22
- package/dist/components/settings/account/account-settings.d.ts +2 -2
- package/dist/components/settings/account/account-settings.js +22 -19
- package/dist/components/settings/account/appearance.d.ts +1 -1
- package/dist/components/settings/account/appearance.js +70 -27
- package/dist/components/settings/account/change-avatar.js +88 -55
- package/dist/components/settings/account/change-email.d.ts +1 -1
- package/dist/components/settings/account/change-email.js +56 -28
- package/dist/components/settings/account/manage-account.d.ts +1 -1
- package/dist/components/settings/account/manage-account.js +50 -31
- package/dist/components/settings/account/manage-accounts.d.ts +1 -1
- package/dist/components/settings/account/manage-accounts.js +32 -36
- package/dist/components/settings/account/user-profile.d.ts +3 -3
- package/dist/components/settings/account/user-profile.js +105 -22
- package/dist/components/settings/security/active-session.d.ts +1 -1
- package/dist/components/settings/security/active-session.js +60 -51
- package/dist/components/settings/security/active-sessions.d.ts +1 -1
- package/dist/components/settings/security/active-sessions.js +32 -26
- package/dist/components/settings/security/change-password.d.ts +1 -1
- package/dist/components/settings/security/change-password.js +189 -76
- package/dist/components/settings/security/danger-zone.d.ts +2 -2
- package/dist/components/settings/security/danger-zone.js +17 -11
- package/dist/components/settings/security/delete-user.d.ts +1 -1
- package/dist/components/settings/security/delete-user.js +96 -46
- package/dist/components/settings/security/linked-account.d.ts +1 -1
- package/dist/components/settings/security/linked-account.js +61 -47
- package/dist/components/settings/security/linked-accounts.d.ts +1 -1
- package/dist/components/settings/security/linked-accounts.js +43 -40
- package/dist/components/settings/security/passkey.d.ts +8 -0
- package/dist/components/settings/security/passkey.js +43 -0
- package/dist/components/settings/security/passkeys.d.ts +6 -0
- package/dist/components/settings/security/passkeys.js +53 -0
- package/dist/components/settings/security/security-settings.d.ts +2 -2
- package/dist/components/settings/security/security-settings.js +24 -20
- package/dist/components/settings/settings.d.ts +3 -3
- package/dist/components/settings/settings.js +44 -27
- package/dist/components/user/switch-account-item.d.ts +1 -1
- package/dist/components/user/switch-account-item.js +19 -15
- package/dist/components/user/switch-account-menu.js +27 -28
- package/dist/components/user/user-avatar.d.ts +3 -3
- package/dist/components/user/user-avatar.js +28 -30
- package/dist/components/user/user-button.d.ts +1 -1
- package/dist/components/user/user-button.js +90 -23
- package/dist/components/user/user-view.d.ts +3 -3
- package/dist/components/user/user-view.js +36 -23
- package/dist/core.d.ts +1 -1
- package/dist/index.d.ts +35 -33
- package/dist/index.js +36 -33
- package/dist/react-exports.d.ts +1 -1
- package/package.json +17 -10
- package/src/components/auth/auth.tsx +1 -1
- package/src/components/auth/magic-link.tsx +4 -0
- package/src/components/auth/passkey-button.tsx +36 -0
- package/src/components/auth/sign-in.tsx +67 -30
- package/src/components/auth/sign-up.tsx +97 -3
- package/src/components/settings/account/user-profile.tsx +121 -6
- package/src/components/settings/security/passkey.tsx +51 -0
- package/src/components/settings/security/passkeys.tsx +104 -0
- package/src/components/settings/security/security-settings.tsx +3 -1
- package/src/components/settings/settings.tsx +1 -1
- package/src/index.tsx +2 -0
- package/dist/components/account/account.d.ts +0 -18
- package/dist/components/account/account.js +0 -24
- package/dist/components/account/settings/account-settings.d.ts +0 -5
- package/dist/components/account/settings/account-settings.js +0 -6
- package/dist/components/account/settings/settings.d.ts +0 -5
- package/dist/components/account/settings/settings.js +0 -5
- package/dist/components/account/settings/user-profile.d.ts +0 -5
- package/dist/components/account/settings/user-profile.js +0 -20
- package/dist/components/settings/account/accounts.d.ts +0 -14
- package/dist/components/settings/account/accounts.js +0 -26
- package/dist/components/settings/account/theme-selector.d.ts +0 -16
- package/dist/components/settings/account/theme-selector.js +0 -33
- package/dist/components/settings/account/theme-settings.d.ts +0 -16
- package/dist/components/settings/account/theme-settings.js +0 -31
- package/dist/components/settings/account-settings.d.ts +0 -5
- package/dist/components/settings/account-settings.js +0 -6
- package/dist/components/settings/account.d.ts +0 -18
- package/dist/components/settings/account.js +0 -24
- package/dist/components/settings/security/connected-account.d.ts +0 -16
- package/dist/components/settings/security/connected-account.js +0 -46
- package/dist/components/settings/security/connected-accounts.d.ts +0 -15
- package/dist/components/settings/security/connected-accounts.js +0 -31
- package/dist/components/settings/security/sessions.d.ts +0 -14
- package/dist/components/settings/security/sessions.js +0 -40
- package/dist/components/settings/settings/account-settings.d.ts +0 -5
- package/dist/components/settings/settings/account-settings.js +0 -6
- package/dist/components/settings/settings/user-profile.d.ts +0 -5
- package/dist/components/settings/settings/user-profile.js +0 -20
- package/dist/components/settings/user-profile.d.ts +0 -5
- package/dist/components/settings/user-profile.js +0 -20
- package/dist/components/user/switch-account-popover.d.ts +0 -10
- package/dist/components/user/switch-account-popover.js +0 -25
- package/dist/components/user/switch-account-submenu.d.ts +0 -10
- package/dist/components/user/switch-account-submenu.js +0 -25
- package/dist/hooks/use-auth.d.ts +0 -2
- package/dist/hooks/use-auth.js +0 -8
- package/dist/hooks/use-redirect-to.d.ts +0 -8
- package/dist/hooks/use-redirect-to.js +0 -19
- package/dist/hooks/use-sign-in.d.ts +0 -8
- package/dist/hooks/use-sign-in.js +0 -53
- package/dist/lib/utils.d.ts +0 -2
- package/dist/lib/utils.js +0 -5
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -1
- package/dist/src/components/auth/auth-provider.d.ts +0 -8
- package/dist/src/components/auth/auth-provider.js +0 -13
- package/dist/src/components/auth/auth.d.ts +0 -22
- package/dist/src/components/auth/auth.js +0 -42
- package/dist/src/components/auth/field-separator.d.ts +0 -4
- package/dist/src/components/auth/field-separator.js +0 -5
- package/dist/src/components/auth/forgot-password.d.ts +0 -15
- package/dist/src/components/auth/forgot-password.js +0 -29
- package/dist/src/components/auth/magic-link-button.d.ts +0 -13
- package/dist/src/components/auth/magic-link-button.js +0 -20
- package/dist/src/components/auth/magic-link.d.ts +0 -17
- package/dist/src/components/auth/magic-link.js +0 -37
- package/dist/src/components/auth/provider-buttons.d.ts +0 -19
- package/dist/src/components/auth/provider-buttons.js +0 -35
- package/dist/src/components/auth/reset-password.d.ts +0 -11
- package/dist/src/components/auth/reset-password.js +0 -59
- package/dist/src/components/auth/sign-in.d.ts +0 -14
- package/dist/src/components/auth/sign-in.js +0 -58
- package/dist/src/components/auth/sign-out.d.ts +0 -11
- package/dist/src/components/auth/sign-out.js +0 -34
- package/dist/src/components/auth/sign-up.d.ts +0 -19
- package/dist/src/components/auth/sign-up.js +0 -65
- package/dist/src/components/email/email-changed-email.d.ts +0 -3
- package/dist/src/components/email/email-changed-email.js +0 -23
- package/dist/src/components/email/email-verification-email.d.ts +0 -3
- package/dist/src/components/email/email-verification-email.js +0 -23
- package/dist/src/components/email/magic-link-email.d.ts +0 -3
- package/dist/src/components/email/magic-link-email.js +0 -23
- package/dist/src/components/email/new-device-email.d.ts +0 -3
- package/dist/src/components/email/new-device-email.js +0 -23
- package/dist/src/components/email/otp-email.d.ts +0 -3
- package/dist/src/components/email/otp-email.js +0 -22
- package/dist/src/components/email/password-changed-email.d.ts +0 -3
- package/dist/src/components/email/password-changed-email.js +0 -23
- package/dist/src/components/email/reset-password-email.d.ts +0 -3
- package/dist/src/components/email/reset-password-email.js +0 -23
- package/dist/src/components/settings/account/account-settings.d.ts +0 -13
- package/dist/src/components/settings/account/account-settings.js +0 -19
- package/dist/src/components/settings/account/appearance.d.ts +0 -16
- package/dist/src/components/settings/account/appearance.js +0 -28
- package/dist/src/components/settings/account/change-email.d.ts +0 -15
- package/dist/src/components/settings/account/change-email.js +0 -35
- package/dist/src/components/settings/account/manage-account.d.ts +0 -19
- package/dist/src/components/settings/account/manage-account.js +0 -27
- package/dist/src/components/settings/account/manage-accounts.d.ts +0 -14
- package/dist/src/components/settings/account/manage-accounts.js +0 -27
- package/dist/src/components/settings/account/user-profile.d.ts +0 -13
- package/dist/src/components/settings/account/user-profile.js +0 -29
- package/dist/src/components/settings/security/active-session.d.ts +0 -14
- package/dist/src/components/settings/security/active-session.js +0 -35
- package/dist/src/components/settings/security/active-sessions.d.ts +0 -14
- package/dist/src/components/settings/security/active-sessions.js +0 -29
- package/dist/src/components/settings/security/change-password.d.ts +0 -15
- package/dist/src/components/settings/security/change-password.js +0 -57
- package/dist/src/components/settings/security/linked-account.d.ts +0 -16
- package/dist/src/components/settings/security/linked-account.js +0 -46
- package/dist/src/components/settings/security/linked-accounts.d.ts +0 -15
- package/dist/src/components/settings/security/linked-accounts.js +0 -31
- package/dist/src/components/settings/security/security-settings.d.ts +0 -15
- package/dist/src/components/settings/security/security-settings.js +0 -18
- package/dist/src/components/settings/settings.d.ts +0 -29
- package/dist/src/components/settings/settings.js +0 -39
- package/dist/src/components/user/switch-account-item.d.ts +0 -16
- package/dist/src/components/user/switch-account-item.js +0 -14
- package/dist/src/components/user/switch-account-menu.d.ts +0 -10
- package/dist/src/components/user/switch-account-menu.js +0 -23
- package/dist/src/components/user/user-avatar.d.ts +0 -24
- package/dist/src/components/user/user-avatar.js +0 -31
- package/dist/src/components/user/user-button.d.ts +0 -21
- package/dist/src/components/user/user-button.js +0 -24
- package/dist/src/components/user/user-view.d.ts +0 -21
- package/dist/src/components/user/user-view.js +0 -24
- package/dist/src/core.d.ts +0 -1
- package/dist/src/core.js +0 -1
- package/dist/src/index.d.ts +0 -31
- package/dist/src/index.js +0 -32
- package/dist/src/lib/utils.d.ts +0 -2
- package/dist/src/lib/utils.js +0 -5
- package/dist/src/react-exports.d.ts +0 -1
- package/dist/src/react-exports.js +0 -1
|
@@ -1,58 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
import { useAuth as e, useResetPassword as t } from "@better-auth-ui/react";
|
|
2
|
+
import { Button as n, Card as r, Description as i, FieldError as a, Form as o, InputGroup as s, Label as c, Link as l, Spinner as u, TextField as d, cn as f, toast as p } from "@heroui/react";
|
|
3
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
4
|
+
import { useEffect as g, useState as _ } from "react";
|
|
5
|
+
import { Eye as v, EyeSlash as y } from "@gravity-ui/icons";
|
|
6
|
+
//#region src/components/auth/reset-password.tsx
|
|
7
|
+
function b({ className: b, variant: x, ...S }) {
|
|
8
|
+
let { basePaths: C, emailAndPassword: w, localization: T, viewPaths: E, navigate: D } = e(), { mutate: O, isPending: k } = t({
|
|
9
|
+
onError: (e) => p.danger(e.error?.message || e.message),
|
|
10
|
+
onSuccess: () => {
|
|
11
|
+
p.success(T.auth.passwordResetSuccess), D({ to: `${C.auth}/${E.auth.signIn}` });
|
|
12
|
+
}
|
|
13
|
+
}), [A, j] = _(!1), [M, N] = _(!1);
|
|
14
|
+
g(() => {
|
|
15
|
+
new URLSearchParams(window.location.search).get("token") || (p.danger(T.auth.invalidResetPasswordToken), D({ to: `${C.auth}/${E.auth.signIn}` }));
|
|
16
|
+
}, [
|
|
17
|
+
C.auth,
|
|
18
|
+
T.auth.invalidResetPasswordToken,
|
|
19
|
+
E.auth.signIn,
|
|
20
|
+
D
|
|
21
|
+
]);
|
|
22
|
+
function P(e) {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
let t = new URLSearchParams(window.location.search).get("token");
|
|
25
|
+
if (!t) {
|
|
26
|
+
p.danger(T.auth.invalidResetPasswordToken), D({ to: `${C.auth}/${E.auth.signIn}` });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let n = new FormData(e.currentTarget), r = n.get("password"), i = n.get("confirmPassword");
|
|
30
|
+
if (w?.confirmPassword && r !== i) {
|
|
31
|
+
p.danger(T.auth.passwordsDoNotMatch);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
O({
|
|
35
|
+
token: t,
|
|
36
|
+
newPassword: r
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ h(r, {
|
|
40
|
+
className: f("w-full max-w-sm p-4 md:p-6", b),
|
|
41
|
+
variant: x,
|
|
42
|
+
...S,
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ m(r.Header, { children: /* @__PURE__ */ m(r.Title, {
|
|
45
|
+
className: "text-xl font-semibold mb-1",
|
|
46
|
+
children: T.auth.resetPassword
|
|
47
|
+
}) }),
|
|
48
|
+
/* @__PURE__ */ m(r.Content, { children: /* @__PURE__ */ h(o, {
|
|
49
|
+
onSubmit: P,
|
|
50
|
+
className: "flex flex-col gap-4",
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ h(d, {
|
|
53
|
+
minLength: w?.minPasswordLength,
|
|
54
|
+
maxLength: w?.maxPasswordLength,
|
|
55
|
+
name: "password",
|
|
56
|
+
autoComplete: "new-password",
|
|
57
|
+
isDisabled: k,
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ m(c, { children: T.auth.password }),
|
|
60
|
+
/* @__PURE__ */ h(s, {
|
|
61
|
+
variant: x === "transparent" ? "primary" : "secondary",
|
|
62
|
+
children: [/* @__PURE__ */ m(s.Input, {
|
|
63
|
+
name: "password",
|
|
64
|
+
placeholder: T.auth.newPasswordPlaceholder,
|
|
65
|
+
type: A ? "text" : "password",
|
|
66
|
+
required: !0
|
|
67
|
+
}), /* @__PURE__ */ m(s.Suffix, {
|
|
68
|
+
className: "px-0",
|
|
69
|
+
children: /* @__PURE__ */ m(n, {
|
|
70
|
+
isIconOnly: !0,
|
|
71
|
+
"aria-label": A ? T.auth.hidePassword : T.auth.showPassword,
|
|
72
|
+
size: "sm",
|
|
73
|
+
variant: "ghost",
|
|
74
|
+
onPress: () => j(!A),
|
|
75
|
+
isDisabled: k,
|
|
76
|
+
children: m(A ? y : v, {})
|
|
77
|
+
})
|
|
78
|
+
})]
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ m(a, {})
|
|
81
|
+
]
|
|
82
|
+
}),
|
|
83
|
+
w?.confirmPassword && /* @__PURE__ */ h(d, {
|
|
84
|
+
minLength: w?.minPasswordLength,
|
|
85
|
+
maxLength: w?.maxPasswordLength,
|
|
86
|
+
name: "confirmPassword",
|
|
87
|
+
autoComplete: "new-password",
|
|
88
|
+
isDisabled: k,
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ m(c, { children: T.auth.confirmPassword }),
|
|
91
|
+
/* @__PURE__ */ h(s, {
|
|
92
|
+
variant: x === "transparent" ? "primary" : "secondary",
|
|
93
|
+
children: [/* @__PURE__ */ m(s.Input, {
|
|
94
|
+
placeholder: T.auth.confirmPasswordPlaceholder,
|
|
95
|
+
type: M ? "text" : "password",
|
|
96
|
+
required: !0,
|
|
97
|
+
name: "confirmPassword"
|
|
98
|
+
}), /* @__PURE__ */ m(s.Suffix, {
|
|
99
|
+
className: "px-0",
|
|
100
|
+
children: /* @__PURE__ */ m(n, {
|
|
101
|
+
isIconOnly: !0,
|
|
102
|
+
"aria-label": M ? T.auth.hidePassword : T.auth.showPassword,
|
|
103
|
+
size: "sm",
|
|
104
|
+
variant: "ghost",
|
|
105
|
+
onPress: () => N(!M),
|
|
106
|
+
isDisabled: k,
|
|
107
|
+
children: m(M ? y : v, {})
|
|
108
|
+
})
|
|
109
|
+
})]
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ m(a, {})
|
|
112
|
+
]
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ m("div", {
|
|
115
|
+
className: "flex flex-col gap-3",
|
|
116
|
+
children: /* @__PURE__ */ h(n, {
|
|
117
|
+
type: "submit",
|
|
118
|
+
className: "w-full",
|
|
119
|
+
isPending: k,
|
|
120
|
+
children: [k && /* @__PURE__ */ m(u, {
|
|
121
|
+
color: "current",
|
|
122
|
+
size: "sm"
|
|
123
|
+
}), T.auth.resetPassword]
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
}) }),
|
|
128
|
+
/* @__PURE__ */ m(r.Footer, {
|
|
129
|
+
className: "flex-col",
|
|
130
|
+
children: /* @__PURE__ */ h(i, {
|
|
131
|
+
className: "text-sm",
|
|
132
|
+
children: [
|
|
133
|
+
T.auth.rememberYourPassword,
|
|
134
|
+
" ",
|
|
135
|
+
/* @__PURE__ */ m(l, {
|
|
136
|
+
href: `${C.auth}/${E.auth.signIn}`,
|
|
137
|
+
className: "text-accent decoration-accent no-underline hover:underline",
|
|
138
|
+
children: T.auth.signIn
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
});
|
|
58
145
|
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { b as ResetPassword };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CardProps } from '@heroui/react';
|
|
2
|
+
import { SocialLayout } from './provider-buttons';
|
|
3
3
|
export interface SignInProps {
|
|
4
4
|
className?: string;
|
|
5
5
|
socialLayout?: SocialLayout;
|
|
@@ -1,64 +1,164 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
export function SignIn({ className, socialLayout, socialPosition = "bottom", variant, ...props }) {
|
|
14
|
-
const { basePaths, baseURL, emailAndPassword, localization, magicLink, redirectTo, socialProviders, viewPaths, navigate } = useAuth();
|
|
15
|
-
const [password, setPassword] = useState("");
|
|
16
|
-
const { mutate: sendVerificationEmail } = useSendVerificationEmail({
|
|
17
|
-
onError: (error) => toast.danger(error.error?.message || error.message),
|
|
18
|
-
onSuccess: () => toast.success(localization.auth.verificationEmailSent)
|
|
19
|
-
});
|
|
20
|
-
const { mutate: signInEmail, isPending: signInPending } = useSignInEmail({
|
|
21
|
-
onError: (error, { email }) => {
|
|
22
|
-
setPassword("");
|
|
23
|
-
if (error.error?.code === "EMAIL_NOT_VERIFIED") {
|
|
24
|
-
toast.danger(error.error?.message || error.message, {
|
|
25
|
-
actionProps: {
|
|
26
|
-
children: localization.auth.resend,
|
|
27
|
-
onClick: () => sendVerificationEmail({
|
|
28
|
-
email,
|
|
29
|
-
callbackURL: `${baseURL}${redirectTo}`
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
toast.danger(error.error?.message || error.message);
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
onSuccess: () => navigate({ to: redirectTo })
|
|
39
|
-
});
|
|
40
|
-
const [socialRedirecting, setSocialRedirecting] = useState(false);
|
|
41
|
-
const { mutate: signInSocial, isPending: socialPending } = useSignInSocial({
|
|
42
|
-
onError: (error) => toast.danger(error.error?.message || error.message),
|
|
43
|
-
onSuccess: () => {
|
|
44
|
-
setSocialRedirecting(true);
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
setSocialRedirecting(false);
|
|
47
|
-
}, 5000);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
const handleSubmit = (e) => {
|
|
51
|
-
e.preventDefault();
|
|
52
|
-
const formData = new FormData(e.currentTarget);
|
|
53
|
-
const email = formData.get("email");
|
|
54
|
-
const rememberMe = formData.get("rememberMe") === "on";
|
|
55
|
-
signInEmail({
|
|
56
|
-
email,
|
|
57
|
-
password,
|
|
58
|
-
...(emailAndPassword?.rememberMe ? { rememberMe } : {})
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
const isPending = signInPending || socialPending || socialRedirecting;
|
|
62
|
-
const showSeparator = emailAndPassword?.enabled && !!socialProviders?.length;
|
|
63
|
-
return (_jsxs(Card, { className: cn("w-full max-w-sm gap-4 md:p-6", className), variant: variant, ...props, children: [_jsx(Card.Header, { children: _jsx(Card.Title, { className: "text-xl font-semibold mb-1", children: localization.auth.signIn }) }), _jsxs(Card.Content, { className: "gap-4", children: [socialPosition === "top" && (_jsxs(_Fragment, { children: [!!socialProviders?.length && (_jsx(ProviderButtons, { socialLayout: socialLayout, signInSocial: signInSocial, isPending: isPending })), showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or }))] })), emailAndPassword?.enabled && (_jsxs(Form, { onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs(TextField, { name: "email", type: "email", autoComplete: "email", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.email }), _jsx(Input, { placeholder: localization.auth.emailPlaceholder, variant: variant === "transparent" ? "primary" : "secondary", required: true }), _jsx(FieldError, {})] }), _jsxs(TextField, { minLength: emailAndPassword?.minPasswordLength, maxLength: emailAndPassword?.maxPasswordLength, name: "password", type: "password", autoComplete: "current-password", isDisabled: isPending, value: password, onChange: setPassword, children: [_jsx(Label, { children: localization.auth.password }), _jsx(Input, { placeholder: localization.auth.passwordPlaceholder, variant: variant === "transparent" ? "primary" : "secondary", required: true }), _jsx(FieldError, {})] }), emailAndPassword?.rememberMe && (_jsxs(Checkbox, { name: "rememberMe", isDisabled: isPending, variant: variant === "transparent" ? "primary" : "secondary", children: [_jsx(Checkbox.Control, { children: _jsx(Checkbox.Indicator, {}) }), _jsx(Checkbox.Content, { children: _jsx(Label, { children: localization.auth.rememberMe }) })] })), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs(Button, { type: "submit", className: "w-full", isPending: isPending, children: [isPending && _jsx(Spinner, { color: "current", size: "sm" }), localization.auth.signIn] }), magicLink && (_jsx(MagicLinkButton, { view: "signIn", isPending: isPending }))] })] })), socialPosition === "bottom" && (_jsxs(_Fragment, { children: [showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or })), !!socialProviders?.length && (_jsx(ProviderButtons, { socialLayout: socialLayout, signInSocial: signInSocial, isPending: isPending }))] }))] }), _jsxs(Card.Footer, { className: "flex-col gap-3", children: [emailAndPassword?.forgotPassword && (_jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.forgotPassword}`, className: "no-underline hover:underline", children: localization.auth.forgotPasswordLink })), emailAndPassword?.enabled && (_jsxs(Description, { className: "text-sm", children: [localization.auth.needToCreateAnAccount, " ", _jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.signUp}`, className: "text-accent no-underline hover:underline decoration-accent-hover", children: localization.auth.signUp })] }))] })] }));
|
|
1
|
+
import { FieldSeparator as e } from "./field-separator.js";
|
|
2
|
+
import { MagicLinkButton as t } from "./magic-link-button.js";
|
|
3
|
+
import { PasskeyButton as n } from "./passkey-button.js";
|
|
4
|
+
import { ProviderButtons as r } from "./provider-buttons.js";
|
|
5
|
+
import { useAuth as i, useSendVerificationEmail as a, useSignInEmail as o, useSignInSocial as s, useSignInUsername as c } from "@better-auth-ui/react";
|
|
6
|
+
import { Button as ee, Card as l, Checkbox as u, Description as te, FieldError as d, Form as f, Input as p, Label as m, Link as h, Spinner as g, TextField as _, cn as v, toast as y } from "@heroui/react";
|
|
7
|
+
import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
8
|
+
import { useState as C } from "react";
|
|
9
|
+
//#region src/components/auth/sign-in.tsx
|
|
10
|
+
function w(e) {
|
|
11
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
|
|
64
12
|
}
|
|
13
|
+
function T({ className: T, socialLayout: E, socialPosition: D = "bottom", variant: O, ...k }) {
|
|
14
|
+
let { basePaths: A, baseURL: j, emailAndPassword: M, localization: N, magicLink: P, passkey: F, redirectTo: I, socialProviders: L, username: R, viewPaths: z, navigate: B } = i(), [V, H] = C(""), { mutate: U } = a({
|
|
15
|
+
onError: (e) => y.danger(e.error?.message || e.message),
|
|
16
|
+
onSuccess: () => y.success(N.auth.verificationEmailSent)
|
|
17
|
+
}), { mutate: W, isPending: G } = o({
|
|
18
|
+
onError: (e, { email: t }) => {
|
|
19
|
+
H(""), e.error?.code === "EMAIL_NOT_VERIFIED" ? y.danger(e.error?.message || e.message, { actionProps: {
|
|
20
|
+
children: N.auth.resend,
|
|
21
|
+
onClick: () => U({
|
|
22
|
+
email: t,
|
|
23
|
+
callbackURL: `${j}${I}`
|
|
24
|
+
})
|
|
25
|
+
} }) : y.danger(e.error?.message || e.message);
|
|
26
|
+
},
|
|
27
|
+
onSuccess: () => B({ to: I })
|
|
28
|
+
}), { mutate: K, isPending: q } = c({
|
|
29
|
+
onError: (e) => {
|
|
30
|
+
H(""), y.danger(e.error?.message || e.message);
|
|
31
|
+
},
|
|
32
|
+
onSuccess: () => B({ to: I })
|
|
33
|
+
}), [J, Y] = C(!1), { mutate: X, isPending: Z } = s({
|
|
34
|
+
onError: (e) => y.danger(e.error?.message || e.message),
|
|
35
|
+
onSuccess: () => {
|
|
36
|
+
Y(!0), setTimeout(() => {
|
|
37
|
+
Y(!1);
|
|
38
|
+
}, 5e3);
|
|
39
|
+
}
|
|
40
|
+
}), ne = (e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
let t = new FormData(e.currentTarget), n = t.get("email"), r = t.get("rememberMe") === "on";
|
|
43
|
+
R?.enabled && !w(n) ? K({
|
|
44
|
+
username: n,
|
|
45
|
+
password: V
|
|
46
|
+
}) : W({
|
|
47
|
+
email: n,
|
|
48
|
+
password: V,
|
|
49
|
+
...M?.rememberMe ? { rememberMe: r } : {}
|
|
50
|
+
});
|
|
51
|
+
}, Q = G || q || Z || J, $ = M?.enabled && !!L?.length;
|
|
52
|
+
return /* @__PURE__ */ S(l, {
|
|
53
|
+
className: v("w-full max-w-sm gap-4 md:p-6", T),
|
|
54
|
+
variant: O,
|
|
55
|
+
...k,
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ x(l.Header, { children: /* @__PURE__ */ x(l.Title, {
|
|
58
|
+
className: "text-xl font-semibold mb-1",
|
|
59
|
+
children: N.auth.signIn
|
|
60
|
+
}) }),
|
|
61
|
+
/* @__PURE__ */ S(l.Content, {
|
|
62
|
+
className: "gap-4",
|
|
63
|
+
children: [
|
|
64
|
+
D === "top" && /* @__PURE__ */ S(b, { children: [!!L?.length && /* @__PURE__ */ x(r, {
|
|
65
|
+
socialLayout: E,
|
|
66
|
+
signInSocial: X,
|
|
67
|
+
isPending: Q
|
|
68
|
+
}), $ && /* @__PURE__ */ x(e, { children: N.auth.or })] }),
|
|
69
|
+
M?.enabled && /* @__PURE__ */ S(f, {
|
|
70
|
+
onSubmit: ne,
|
|
71
|
+
className: "flex flex-col gap-4",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ S(_, {
|
|
74
|
+
name: "email",
|
|
75
|
+
type: R?.enabled ? "text" : "email",
|
|
76
|
+
autoComplete: R?.enabled ? "username" : "email",
|
|
77
|
+
isDisabled: Q,
|
|
78
|
+
children: [
|
|
79
|
+
/* @__PURE__ */ x(m, { children: R?.enabled ? N.auth.username : N.auth.email }),
|
|
80
|
+
/* @__PURE__ */ x(p, {
|
|
81
|
+
placeholder: R?.enabled ? N.auth.usernameOrEmailPlaceholder : N.auth.emailPlaceholder,
|
|
82
|
+
variant: O === "transparent" ? "primary" : "secondary",
|
|
83
|
+
required: !0
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ x(d, {})
|
|
86
|
+
]
|
|
87
|
+
}),
|
|
88
|
+
/* @__PURE__ */ S(_, {
|
|
89
|
+
minLength: M?.minPasswordLength,
|
|
90
|
+
maxLength: M?.maxPasswordLength,
|
|
91
|
+
name: "password",
|
|
92
|
+
type: "password",
|
|
93
|
+
autoComplete: "current-password",
|
|
94
|
+
isDisabled: Q,
|
|
95
|
+
value: V,
|
|
96
|
+
onChange: H,
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ x(m, { children: N.auth.password }),
|
|
99
|
+
/* @__PURE__ */ x(p, {
|
|
100
|
+
placeholder: N.auth.passwordPlaceholder,
|
|
101
|
+
variant: O === "transparent" ? "primary" : "secondary",
|
|
102
|
+
required: !0
|
|
103
|
+
}),
|
|
104
|
+
/* @__PURE__ */ x(d, {})
|
|
105
|
+
]
|
|
106
|
+
}),
|
|
107
|
+
M?.rememberMe && /* @__PURE__ */ S(u, {
|
|
108
|
+
name: "rememberMe",
|
|
109
|
+
isDisabled: Q,
|
|
110
|
+
variant: O === "transparent" ? "primary" : "secondary",
|
|
111
|
+
children: [/* @__PURE__ */ x(u.Control, { children: /* @__PURE__ */ x(u.Indicator, {}) }), /* @__PURE__ */ x(u.Content, { children: /* @__PURE__ */ x(m, { children: N.auth.rememberMe }) })]
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ S("div", {
|
|
114
|
+
className: "flex flex-col gap-3",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ S(ee, {
|
|
117
|
+
type: "submit",
|
|
118
|
+
className: "w-full",
|
|
119
|
+
isPending: Q,
|
|
120
|
+
children: [Q && /* @__PURE__ */ x(g, {
|
|
121
|
+
color: "current",
|
|
122
|
+
size: "sm"
|
|
123
|
+
}), N.auth.signIn]
|
|
124
|
+
}),
|
|
125
|
+
P && /* @__PURE__ */ x(t, {
|
|
126
|
+
view: "signIn",
|
|
127
|
+
isPending: Q
|
|
128
|
+
}),
|
|
129
|
+
F && /* @__PURE__ */ x(n, { isPending: Q })
|
|
130
|
+
]
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
}),
|
|
134
|
+
D === "bottom" && /* @__PURE__ */ S(b, { children: [$ && /* @__PURE__ */ x(e, { children: N.auth.or }), !!L?.length && /* @__PURE__ */ x(r, {
|
|
135
|
+
socialLayout: E,
|
|
136
|
+
signInSocial: X,
|
|
137
|
+
isPending: Q
|
|
138
|
+
})] })
|
|
139
|
+
]
|
|
140
|
+
}),
|
|
141
|
+
/* @__PURE__ */ S(l.Footer, {
|
|
142
|
+
className: "flex-col gap-3",
|
|
143
|
+
children: [M?.forgotPassword && /* @__PURE__ */ x(h, {
|
|
144
|
+
href: `${A.auth}/${z.auth.forgotPassword}`,
|
|
145
|
+
className: "no-underline hover:underline",
|
|
146
|
+
children: N.auth.forgotPasswordLink
|
|
147
|
+
}), M?.enabled && /* @__PURE__ */ S(te, {
|
|
148
|
+
className: "text-sm",
|
|
149
|
+
children: [
|
|
150
|
+
N.auth.needToCreateAnAccount,
|
|
151
|
+
" ",
|
|
152
|
+
/* @__PURE__ */ x(h, {
|
|
153
|
+
href: `${A.auth}/${z.auth.signUp}`,
|
|
154
|
+
className: "text-accent no-underline hover:underline decoration-accent-hover",
|
|
155
|
+
children: N.auth.signUp
|
|
156
|
+
})
|
|
157
|
+
]
|
|
158
|
+
})]
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
export { T as SignIn };
|
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect, useRef } from "react";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const hasSignedOut = useRef(false);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (hasSignedOut.current)
|
|
28
|
-
return;
|
|
29
|
-
hasSignedOut.current = true;
|
|
30
|
-
signOut();
|
|
31
|
-
}, [signOut]);
|
|
32
|
-
return (_jsx(Spinner, { className: cn("mx-auto my-auto", className), color: "current" }));
|
|
1
|
+
import { useAuth as e, useSignOut as t } from "@better-auth-ui/react";
|
|
2
|
+
import { Spinner as n, cn as r, toast as i } from "@heroui/react";
|
|
3
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
4
|
+
import { useEffect as o, useRef as s } from "react";
|
|
5
|
+
//#region src/components/auth/sign-out.tsx
|
|
6
|
+
function c({ className: c }) {
|
|
7
|
+
let { basePaths: l, navigate: u, viewPaths: d } = e(), { mutate: f } = t({
|
|
8
|
+
onError: (e) => {
|
|
9
|
+
i.danger(e.error?.message || e.message), u({
|
|
10
|
+
to: `${l.auth}/${d.auth.signIn}`,
|
|
11
|
+
replace: !0
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
onSuccess: () => u({
|
|
15
|
+
to: `${l.auth}/${d.auth.signIn}`,
|
|
16
|
+
replace: !0
|
|
17
|
+
})
|
|
18
|
+
}), p = s(!1);
|
|
19
|
+
return o(() => {
|
|
20
|
+
p.current || (p.current = !0, f());
|
|
21
|
+
}, [f]), /* @__PURE__ */ a(n, {
|
|
22
|
+
className: r("mx-auto my-auto", c),
|
|
23
|
+
color: "current"
|
|
24
|
+
});
|
|
33
25
|
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { c as SignOut };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CardProps } from '@heroui/react';
|
|
2
|
+
import { SocialLayout } from './provider-buttons';
|
|
3
3
|
export type SignUpProps = {
|
|
4
4
|
className?: string;
|
|
5
5
|
socialLayout?: SocialLayout;
|