@better-auth-ui/heroui 1.6.0
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/account/account.d.ts +18 -0
- package/dist/components/account/account.js +24 -0
- package/dist/components/account/settings/account-settings.d.ts +5 -0
- package/dist/components/account/settings/account-settings.js +6 -0
- package/dist/components/account/settings/settings.d.ts +5 -0
- package/dist/components/account/settings/settings.js +5 -0
- package/dist/components/account/settings/user-profile.d.ts +5 -0
- package/dist/components/account/settings/user-profile.js +20 -0
- package/dist/components/auth/auth-provider.d.ts +9 -0
- package/dist/components/auth/auth-provider.js +12 -0
- package/dist/components/auth/auth.d.ts +23 -0
- package/dist/components/auth/auth.js +42 -0
- package/dist/components/auth/field-separator.d.ts +4 -0
- package/dist/components/auth/field-separator.js +5 -0
- package/dist/components/auth/forgot-password.d.ts +15 -0
- package/dist/components/auth/forgot-password.js +28 -0
- package/dist/components/auth/magic-link-button.d.ts +13 -0
- package/dist/components/auth/magic-link-button.js +19 -0
- package/dist/components/auth/magic-link.d.ts +17 -0
- package/dist/components/auth/magic-link.js +43 -0
- package/dist/components/auth/provider-buttons.d.ts +19 -0
- package/dist/components/auth/provider-buttons.js +34 -0
- package/dist/components/auth/reset-password.d.ts +11 -0
- package/dist/components/auth/reset-password.js +58 -0
- package/dist/components/auth/sign-in.d.ts +14 -0
- package/dist/components/auth/sign-in.js +64 -0
- package/dist/components/auth/sign-out.d.ts +9 -0
- package/dist/components/auth/sign-out.js +33 -0
- package/dist/components/auth/sign-up.d.ts +19 -0
- package/dist/components/auth/sign-up.js +71 -0
- package/dist/components/email/email-changed-email.d.ts +3 -0
- package/dist/components/email/email-changed-email.js +23 -0
- package/dist/components/email/email-verification-email.d.ts +3 -0
- package/dist/components/email/email-verification-email.js +23 -0
- package/dist/components/email/magic-link-email.d.ts +3 -0
- package/dist/components/email/magic-link-email.js +23 -0
- package/dist/components/email/new-device-email.d.ts +3 -0
- package/dist/components/email/new-device-email.js +23 -0
- package/dist/components/email/otp-email.d.ts +3 -0
- package/dist/components/email/otp-email.js +22 -0
- package/dist/components/email/password-changed-email.d.ts +3 -0
- package/dist/components/email/password-changed-email.js +23 -0
- package/dist/components/email/reset-password-email.d.ts +3 -0
- package/dist/components/email/reset-password-email.js +23 -0
- package/dist/components/settings/account/account-settings.d.ts +16 -0
- package/dist/components/settings/account/account-settings.js +20 -0
- package/dist/components/settings/account/accounts.d.ts +14 -0
- package/dist/components/settings/account/accounts.js +26 -0
- package/dist/components/settings/account/appearance.d.ts +16 -0
- package/dist/components/settings/account/appearance.js +28 -0
- package/dist/components/settings/account/change-avatar.d.ts +4 -0
- package/dist/components/settings/account/change-avatar.js +56 -0
- package/dist/components/settings/account/change-email.d.ts +15 -0
- package/dist/components/settings/account/change-email.js +29 -0
- package/dist/components/settings/account/manage-account.d.ts +19 -0
- package/dist/components/settings/account/manage-account.js +32 -0
- package/dist/components/settings/account/manage-accounts.d.ts +14 -0
- package/dist/components/settings/account/manage-accounts.js +37 -0
- package/dist/components/settings/account/theme-selector.d.ts +16 -0
- package/dist/components/settings/account/theme-selector.js +33 -0
- package/dist/components/settings/account/theme-settings.d.ts +16 -0
- package/dist/components/settings/account/theme-settings.js +31 -0
- package/dist/components/settings/account/user-profile.d.ts +11 -0
- package/dist/components/settings/account/user-profile.js +23 -0
- package/dist/components/settings/account-settings.d.ts +5 -0
- package/dist/components/settings/account-settings.js +6 -0
- package/dist/components/settings/account.d.ts +18 -0
- package/dist/components/settings/account.js +24 -0
- package/dist/components/settings/security/active-session.d.ts +14 -0
- package/dist/components/settings/security/active-session.js +53 -0
- package/dist/components/settings/security/active-sessions.d.ts +14 -0
- package/dist/components/settings/security/active-sessions.js +28 -0
- package/dist/components/settings/security/change-password.d.ts +15 -0
- package/dist/components/settings/security/change-password.js +79 -0
- package/dist/components/settings/security/connected-account.d.ts +16 -0
- package/dist/components/settings/security/connected-account.js +46 -0
- package/dist/components/settings/security/connected-accounts.d.ts +15 -0
- package/dist/components/settings/security/connected-accounts.js +31 -0
- package/dist/components/settings/security/danger-zone.d.ts +11 -0
- package/dist/components/settings/security/danger-zone.js +12 -0
- package/dist/components/settings/security/delete-user.d.ts +9 -0
- package/dist/components/settings/security/delete-user.js +47 -0
- package/dist/components/settings/security/linked-account.d.ts +16 -0
- package/dist/components/settings/security/linked-account.js +48 -0
- package/dist/components/settings/security/linked-accounts.d.ts +15 -0
- package/dist/components/settings/security/linked-accounts.js +42 -0
- package/dist/components/settings/security/security-settings.d.ts +17 -0
- package/dist/components/settings/security/security-settings.js +21 -0
- package/dist/components/settings/security/sessions.d.ts +14 -0
- package/dist/components/settings/security/sessions.js +40 -0
- package/dist/components/settings/settings/account-settings.d.ts +5 -0
- package/dist/components/settings/settings/account-settings.js +6 -0
- package/dist/components/settings/settings/user-profile.d.ts +5 -0
- package/dist/components/settings/settings/user-profile.js +20 -0
- package/dist/components/settings/settings.d.ts +24 -0
- package/dist/components/settings/settings.js +28 -0
- package/dist/components/settings/user-profile.d.ts +5 -0
- package/dist/components/settings/user-profile.js +20 -0
- package/dist/components/user/switch-account-item.d.ts +16 -0
- package/dist/components/user/switch-account-item.js +16 -0
- package/dist/components/user/switch-account-menu.d.ts +10 -0
- package/dist/components/user/switch-account-menu.js +29 -0
- package/dist/components/user/switch-account-popover.d.ts +10 -0
- package/dist/components/user/switch-account-popover.js +25 -0
- package/dist/components/user/switch-account-submenu.d.ts +10 -0
- package/dist/components/user/switch-account-submenu.js +25 -0
- package/dist/components/user/user-avatar.d.ts +25 -0
- package/dist/components/user/user-avatar.js +31 -0
- package/dist/components/user/user-button.d.ts +25 -0
- package/dist/components/user/user-button.js +24 -0
- package/dist/components/user/user-view.d.ts +22 -0
- package/dist/components/user/user-view.js +24 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/hooks/use-auth.d.ts +2 -0
- package/dist/hooks/use-auth.js +8 -0
- package/dist/hooks/use-redirect-to.d.ts +8 -0
- package/dist/hooks/use-redirect-to.js +19 -0
- package/dist/hooks/use-sign-in.d.ts +8 -0
- package/dist/hooks/use-sign-in.js +53 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +34 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/dist/react-exports.d.ts +1 -0
- package/dist/react-exports.js +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +1 -0
- package/dist/src/components/auth/auth-provider.d.ts +8 -0
- package/dist/src/components/auth/auth-provider.js +13 -0
- package/dist/src/components/auth/auth.d.ts +22 -0
- package/dist/src/components/auth/auth.js +42 -0
- package/dist/src/components/auth/field-separator.d.ts +4 -0
- package/dist/src/components/auth/field-separator.js +5 -0
- package/dist/src/components/auth/forgot-password.d.ts +15 -0
- package/dist/src/components/auth/forgot-password.js +29 -0
- package/dist/src/components/auth/magic-link-button.d.ts +13 -0
- package/dist/src/components/auth/magic-link-button.js +20 -0
- package/dist/src/components/auth/magic-link.d.ts +17 -0
- package/dist/src/components/auth/magic-link.js +37 -0
- package/dist/src/components/auth/provider-buttons.d.ts +19 -0
- package/dist/src/components/auth/provider-buttons.js +35 -0
- package/dist/src/components/auth/reset-password.d.ts +11 -0
- package/dist/src/components/auth/reset-password.js +59 -0
- package/dist/src/components/auth/sign-in.d.ts +14 -0
- package/dist/src/components/auth/sign-in.js +58 -0
- package/dist/src/components/auth/sign-out.d.ts +11 -0
- package/dist/src/components/auth/sign-out.js +34 -0
- package/dist/src/components/auth/sign-up.d.ts +19 -0
- package/dist/src/components/auth/sign-up.js +65 -0
- package/dist/src/components/email/email-changed-email.d.ts +3 -0
- package/dist/src/components/email/email-changed-email.js +23 -0
- package/dist/src/components/email/email-verification-email.d.ts +3 -0
- package/dist/src/components/email/email-verification-email.js +23 -0
- package/dist/src/components/email/magic-link-email.d.ts +3 -0
- package/dist/src/components/email/magic-link-email.js +23 -0
- package/dist/src/components/email/new-device-email.d.ts +3 -0
- package/dist/src/components/email/new-device-email.js +23 -0
- package/dist/src/components/email/otp-email.d.ts +3 -0
- package/dist/src/components/email/otp-email.js +22 -0
- package/dist/src/components/email/password-changed-email.d.ts +3 -0
- package/dist/src/components/email/password-changed-email.js +23 -0
- package/dist/src/components/email/reset-password-email.d.ts +3 -0
- package/dist/src/components/email/reset-password-email.js +23 -0
- package/dist/src/components/settings/account/account-settings.d.ts +13 -0
- package/dist/src/components/settings/account/account-settings.js +19 -0
- package/dist/src/components/settings/account/appearance.d.ts +16 -0
- package/dist/src/components/settings/account/appearance.js +28 -0
- package/dist/src/components/settings/account/change-email.d.ts +15 -0
- package/dist/src/components/settings/account/change-email.js +35 -0
- package/dist/src/components/settings/account/manage-account.d.ts +19 -0
- package/dist/src/components/settings/account/manage-account.js +27 -0
- package/dist/src/components/settings/account/manage-accounts.d.ts +14 -0
- package/dist/src/components/settings/account/manage-accounts.js +27 -0
- package/dist/src/components/settings/account/user-profile.d.ts +13 -0
- package/dist/src/components/settings/account/user-profile.js +29 -0
- package/dist/src/components/settings/security/active-session.d.ts +14 -0
- package/dist/src/components/settings/security/active-session.js +35 -0
- package/dist/src/components/settings/security/active-sessions.d.ts +14 -0
- package/dist/src/components/settings/security/active-sessions.js +29 -0
- package/dist/src/components/settings/security/change-password.d.ts +15 -0
- package/dist/src/components/settings/security/change-password.js +57 -0
- package/dist/src/components/settings/security/linked-account.d.ts +16 -0
- package/dist/src/components/settings/security/linked-account.js +46 -0
- package/dist/src/components/settings/security/linked-accounts.d.ts +15 -0
- package/dist/src/components/settings/security/linked-accounts.js +31 -0
- package/dist/src/components/settings/security/security-settings.d.ts +15 -0
- package/dist/src/components/settings/security/security-settings.js +18 -0
- package/dist/src/components/settings/settings.d.ts +29 -0
- package/dist/src/components/settings/settings.js +39 -0
- package/dist/src/components/user/switch-account-item.d.ts +16 -0
- package/dist/src/components/user/switch-account-item.js +14 -0
- package/dist/src/components/user/switch-account-menu.d.ts +10 -0
- package/dist/src/components/user/switch-account-menu.js +23 -0
- package/dist/src/components/user/user-avatar.d.ts +24 -0
- package/dist/src/components/user/user-avatar.js +31 -0
- package/dist/src/components/user/user-button.d.ts +21 -0
- package/dist/src/components/user/user-button.js +24 -0
- package/dist/src/components/user/user-view.d.ts +21 -0
- package/dist/src/components/user/user-view.js +24 -0
- package/dist/src/core.d.ts +1 -0
- package/dist/src/core.js +1 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.js +32 -0
- package/dist/src/lib/utils.d.ts +2 -0
- package/dist/src/lib/utils.js +5 -0
- package/dist/src/react-exports.d.ts +1 -0
- package/dist/src/react-exports.js +1 -0
- package/dist/styles.css +1 -0
- package/package.json +63 -0
- package/src/components/auth/auth-provider.tsx +27 -0
- package/src/components/auth/auth.tsx +87 -0
- package/src/components/auth/field-separator.tsx +14 -0
- package/src/components/auth/forgot-password.tsx +107 -0
- package/src/components/auth/magic-link-button.tsx +43 -0
- package/src/components/auth/magic-link.tsx +181 -0
- package/src/components/auth/provider-buttons.tsx +85 -0
- package/src/components/auth/reset-password.tsx +210 -0
- package/src/components/auth/sign-in.tsx +260 -0
- package/src/components/auth/sign-out.tsx +44 -0
- package/src/components/auth/sign-up.tsx +314 -0
- package/src/components/email/email-changed-email.tsx +38 -0
- package/src/components/email/email-verification-email.tsx +38 -0
- package/src/components/email/magic-link-email.tsx +38 -0
- package/src/components/email/new-device-email.tsx +38 -0
- package/src/components/email/otp-email.tsx +33 -0
- package/src/components/email/password-changed-email.tsx +38 -0
- package/src/components/email/reset-password-email.tsx +38 -0
- package/src/components/settings/account/account-settings.tsx +48 -0
- package/src/components/settings/account/appearance.tsx +157 -0
- package/src/components/settings/account/change-avatar.tsx +142 -0
- package/src/components/settings/account/change-email.tsx +111 -0
- package/src/components/settings/account/manage-account.tsx +123 -0
- package/src/components/settings/account/manage-accounts.tsx +78 -0
- package/src/components/settings/account/user-profile.tsx +103 -0
- package/src/components/settings/security/active-session.tsx +123 -0
- package/src/components/settings/security/active-sessions.tsx +77 -0
- package/src/components/settings/security/change-password.tsx +335 -0
- package/src/components/settings/security/danger-zone.tsx +32 -0
- package/src/components/settings/security/delete-user.tsx +187 -0
- package/src/components/settings/security/linked-account.tsx +136 -0
- package/src/components/settings/security/linked-accounts.tsx +98 -0
- package/src/components/settings/security/security-settings.tsx +43 -0
- package/src/components/settings/settings.tsx +96 -0
- package/src/components/user/switch-account-item.tsx +39 -0
- package/src/components/user/switch-account-menu.tsx +64 -0
- package/src/components/user/user-avatar.tsx +88 -0
- package/src/components/user/user-button.tsx +221 -0
- package/src/components/user/user-view.tsx +74 -0
- package/src/core.ts +1 -0
- package/src/index.tsx +35 -0
- package/src/react-exports.ts +1 -0
- package/src/styles.css +1 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuth,
|
|
3
|
+
useSendVerificationEmail,
|
|
4
|
+
useSignInEmail,
|
|
5
|
+
useSignInSocial
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import {
|
|
8
|
+
Button,
|
|
9
|
+
Card,
|
|
10
|
+
type CardProps,
|
|
11
|
+
Checkbox,
|
|
12
|
+
cn,
|
|
13
|
+
Description,
|
|
14
|
+
FieldError,
|
|
15
|
+
Form,
|
|
16
|
+
Input,
|
|
17
|
+
Label,
|
|
18
|
+
Link,
|
|
19
|
+
Spinner,
|
|
20
|
+
TextField,
|
|
21
|
+
toast
|
|
22
|
+
} from "@heroui/react"
|
|
23
|
+
import { type SyntheticEvent, useState } from "react"
|
|
24
|
+
|
|
25
|
+
import { FieldSeparator } from "./field-separator"
|
|
26
|
+
import { MagicLinkButton } from "./magic-link-button"
|
|
27
|
+
import { ProviderButtons, type SocialLayout } from "./provider-buttons"
|
|
28
|
+
|
|
29
|
+
export interface SignInProps {
|
|
30
|
+
className?: string
|
|
31
|
+
socialLayout?: SocialLayout
|
|
32
|
+
socialPosition?: "top" | "bottom"
|
|
33
|
+
variant?: CardProps["variant"]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render the sign-in UI using auth context for configuration and localization.
|
|
38
|
+
*
|
|
39
|
+
* @returns The sign-in JSX element containing email/password fields, optional magic-link button, and social provider buttons.
|
|
40
|
+
*/
|
|
41
|
+
export function SignIn({
|
|
42
|
+
className,
|
|
43
|
+
socialLayout,
|
|
44
|
+
socialPosition = "bottom",
|
|
45
|
+
variant,
|
|
46
|
+
...props
|
|
47
|
+
}: SignInProps & CardProps) {
|
|
48
|
+
const {
|
|
49
|
+
basePaths,
|
|
50
|
+
baseURL,
|
|
51
|
+
emailAndPassword,
|
|
52
|
+
localization,
|
|
53
|
+
magicLink,
|
|
54
|
+
redirectTo,
|
|
55
|
+
socialProviders,
|
|
56
|
+
viewPaths,
|
|
57
|
+
navigate
|
|
58
|
+
} = useAuth()
|
|
59
|
+
|
|
60
|
+
const [password, setPassword] = useState("")
|
|
61
|
+
|
|
62
|
+
const { mutate: sendVerificationEmail } = useSendVerificationEmail({
|
|
63
|
+
onError: (error) => toast.danger(error.error?.message || error.message),
|
|
64
|
+
onSuccess: () => toast.success(localization.auth.verificationEmailSent)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const { mutate: signInEmail, isPending: signInPending } = useSignInEmail({
|
|
68
|
+
onError: (error, { email }) => {
|
|
69
|
+
setPassword("")
|
|
70
|
+
|
|
71
|
+
if (error.error?.code === "EMAIL_NOT_VERIFIED") {
|
|
72
|
+
toast.danger(error.error?.message || error.message, {
|
|
73
|
+
actionProps: {
|
|
74
|
+
children: localization.auth.resend,
|
|
75
|
+
onClick: () =>
|
|
76
|
+
sendVerificationEmail({
|
|
77
|
+
email,
|
|
78
|
+
callbackURL: `${baseURL}${redirectTo}`
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
} else {
|
|
83
|
+
toast.danger(error.error?.message || error.message)
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
onSuccess: () => navigate({ to: redirectTo })
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const [socialRedirecting, setSocialRedirecting] = useState(false)
|
|
90
|
+
|
|
91
|
+
const { mutate: signInSocial, isPending: socialPending } = useSignInSocial({
|
|
92
|
+
onError: (error) => toast.danger(error.error?.message || error.message),
|
|
93
|
+
onSuccess: () => {
|
|
94
|
+
setSocialRedirecting(true)
|
|
95
|
+
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
setSocialRedirecting(false)
|
|
98
|
+
}, 5000)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
|
|
105
|
+
const formData = new FormData(e.currentTarget)
|
|
106
|
+
const email = formData.get("email") as string
|
|
107
|
+
const rememberMe = formData.get("rememberMe") === "on"
|
|
108
|
+
|
|
109
|
+
signInEmail({
|
|
110
|
+
email,
|
|
111
|
+
password,
|
|
112
|
+
...(emailAndPassword?.rememberMe ? { rememberMe } : {})
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const isPending = signInPending || socialPending || socialRedirecting
|
|
117
|
+
|
|
118
|
+
const showSeparator = emailAndPassword?.enabled && !!socialProviders?.length
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Card
|
|
122
|
+
className={cn("w-full max-w-sm gap-4 md:p-6", className)}
|
|
123
|
+
variant={variant}
|
|
124
|
+
{...props}
|
|
125
|
+
>
|
|
126
|
+
<Card.Header>
|
|
127
|
+
<Card.Title className="text-xl font-semibold mb-1">
|
|
128
|
+
{localization.auth.signIn}
|
|
129
|
+
</Card.Title>
|
|
130
|
+
</Card.Header>
|
|
131
|
+
|
|
132
|
+
<Card.Content className="gap-4">
|
|
133
|
+
{socialPosition === "top" && (
|
|
134
|
+
<>
|
|
135
|
+
{!!socialProviders?.length && (
|
|
136
|
+
<ProviderButtons
|
|
137
|
+
socialLayout={socialLayout}
|
|
138
|
+
signInSocial={signInSocial}
|
|
139
|
+
isPending={isPending}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
|
|
143
|
+
{showSeparator && (
|
|
144
|
+
<FieldSeparator>{localization.auth.or}</FieldSeparator>
|
|
145
|
+
)}
|
|
146
|
+
</>
|
|
147
|
+
)}
|
|
148
|
+
|
|
149
|
+
{emailAndPassword?.enabled && (
|
|
150
|
+
<Form onSubmit={handleSubmit} className="flex flex-col gap-4">
|
|
151
|
+
<TextField
|
|
152
|
+
name="email"
|
|
153
|
+
type="email"
|
|
154
|
+
autoComplete="email"
|
|
155
|
+
isDisabled={isPending}
|
|
156
|
+
>
|
|
157
|
+
<Label>{localization.auth.email}</Label>
|
|
158
|
+
|
|
159
|
+
<Input
|
|
160
|
+
placeholder={localization.auth.emailPlaceholder}
|
|
161
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
162
|
+
required
|
|
163
|
+
/>
|
|
164
|
+
|
|
165
|
+
<FieldError />
|
|
166
|
+
</TextField>
|
|
167
|
+
|
|
168
|
+
<TextField
|
|
169
|
+
minLength={emailAndPassword?.minPasswordLength}
|
|
170
|
+
maxLength={emailAndPassword?.maxPasswordLength}
|
|
171
|
+
name="password"
|
|
172
|
+
type="password"
|
|
173
|
+
autoComplete="current-password"
|
|
174
|
+
isDisabled={isPending}
|
|
175
|
+
value={password}
|
|
176
|
+
onChange={setPassword}
|
|
177
|
+
>
|
|
178
|
+
<Label>{localization.auth.password}</Label>
|
|
179
|
+
|
|
180
|
+
<Input
|
|
181
|
+
placeholder={localization.auth.passwordPlaceholder}
|
|
182
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
183
|
+
required
|
|
184
|
+
/>
|
|
185
|
+
|
|
186
|
+
<FieldError />
|
|
187
|
+
</TextField>
|
|
188
|
+
|
|
189
|
+
{emailAndPassword?.rememberMe && (
|
|
190
|
+
<Checkbox
|
|
191
|
+
name="rememberMe"
|
|
192
|
+
isDisabled={isPending}
|
|
193
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
194
|
+
>
|
|
195
|
+
<Checkbox.Control>
|
|
196
|
+
<Checkbox.Indicator />
|
|
197
|
+
</Checkbox.Control>
|
|
198
|
+
|
|
199
|
+
<Checkbox.Content>
|
|
200
|
+
<Label>{localization.auth.rememberMe}</Label>
|
|
201
|
+
</Checkbox.Content>
|
|
202
|
+
</Checkbox>
|
|
203
|
+
)}
|
|
204
|
+
|
|
205
|
+
<div className="flex flex-col gap-3">
|
|
206
|
+
<Button type="submit" className="w-full" isPending={isPending}>
|
|
207
|
+
{isPending && <Spinner color="current" size="sm" />}
|
|
208
|
+
|
|
209
|
+
{localization.auth.signIn}
|
|
210
|
+
</Button>
|
|
211
|
+
|
|
212
|
+
{magicLink && (
|
|
213
|
+
<MagicLinkButton view="signIn" isPending={isPending} />
|
|
214
|
+
)}
|
|
215
|
+
</div>
|
|
216
|
+
</Form>
|
|
217
|
+
)}
|
|
218
|
+
|
|
219
|
+
{socialPosition === "bottom" && (
|
|
220
|
+
<>
|
|
221
|
+
{showSeparator && (
|
|
222
|
+
<FieldSeparator>{localization.auth.or}</FieldSeparator>
|
|
223
|
+
)}
|
|
224
|
+
|
|
225
|
+
{!!socialProviders?.length && (
|
|
226
|
+
<ProviderButtons
|
|
227
|
+
socialLayout={socialLayout}
|
|
228
|
+
signInSocial={signInSocial}
|
|
229
|
+
isPending={isPending}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
</>
|
|
233
|
+
)}
|
|
234
|
+
</Card.Content>
|
|
235
|
+
|
|
236
|
+
<Card.Footer className="flex-col gap-3">
|
|
237
|
+
{emailAndPassword?.forgotPassword && (
|
|
238
|
+
<Link
|
|
239
|
+
href={`${basePaths.auth}/${viewPaths.auth.forgotPassword}`}
|
|
240
|
+
className="no-underline hover:underline"
|
|
241
|
+
>
|
|
242
|
+
{localization.auth.forgotPasswordLink}
|
|
243
|
+
</Link>
|
|
244
|
+
)}
|
|
245
|
+
|
|
246
|
+
{emailAndPassword?.enabled && (
|
|
247
|
+
<Description className="text-sm">
|
|
248
|
+
{localization.auth.needToCreateAnAccount}{" "}
|
|
249
|
+
<Link
|
|
250
|
+
href={`${basePaths.auth}/${viewPaths.auth.signUp}`}
|
|
251
|
+
className="text-accent no-underline hover:underline decoration-accent-hover"
|
|
252
|
+
>
|
|
253
|
+
{localization.auth.signUp}
|
|
254
|
+
</Link>
|
|
255
|
+
</Description>
|
|
256
|
+
)}
|
|
257
|
+
</Card.Footer>
|
|
258
|
+
</Card>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useAuth, useSignOut } from "@better-auth-ui/react"
|
|
2
|
+
import { cn, Spinner, toast } from "@heroui/react"
|
|
3
|
+
import { useEffect, useRef } from "react"
|
|
4
|
+
|
|
5
|
+
export type SignOutProps = {
|
|
6
|
+
className?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initiates sign-out on mount and renders a loading card while sign-out proceeds.
|
|
11
|
+
*
|
|
12
|
+
* @returns A Card containing a centered Spinner shown during the sign-out process
|
|
13
|
+
*/
|
|
14
|
+
export function SignOut({ className }: SignOutProps) {
|
|
15
|
+
const { basePaths, navigate, viewPaths } = useAuth()
|
|
16
|
+
|
|
17
|
+
const { mutate: signOut } = useSignOut({
|
|
18
|
+
onError: (error) => {
|
|
19
|
+
toast.danger(error.error?.message || error.message)
|
|
20
|
+
navigate({
|
|
21
|
+
to: `${basePaths.auth}/${viewPaths.auth.signIn}`,
|
|
22
|
+
replace: true
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
onSuccess: () =>
|
|
26
|
+
navigate({
|
|
27
|
+
to: `${basePaths.auth}/${viewPaths.auth.signIn}`,
|
|
28
|
+
replace: true
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const hasSignedOut = useRef(false)
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (hasSignedOut.current) return
|
|
36
|
+
hasSignedOut.current = true
|
|
37
|
+
|
|
38
|
+
signOut()
|
|
39
|
+
}, [signOut])
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Spinner className={cn("mx-auto my-auto", className)} color="current" />
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { useAuth, useSignInSocial, useSignUpEmail } from "@better-auth-ui/react"
|
|
2
|
+
import { Eye, EyeSlash } from "@gravity-ui/icons"
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Card,
|
|
6
|
+
type CardProps,
|
|
7
|
+
cn,
|
|
8
|
+
Description,
|
|
9
|
+
FieldError,
|
|
10
|
+
Form,
|
|
11
|
+
Input,
|
|
12
|
+
InputGroup,
|
|
13
|
+
Label,
|
|
14
|
+
Link,
|
|
15
|
+
Spinner,
|
|
16
|
+
TextField,
|
|
17
|
+
toast
|
|
18
|
+
} from "@heroui/react"
|
|
19
|
+
import { type SyntheticEvent, useState } from "react"
|
|
20
|
+
|
|
21
|
+
import { FieldSeparator } from "./field-separator"
|
|
22
|
+
import { MagicLinkButton } from "./magic-link-button"
|
|
23
|
+
import { ProviderButtons, type SocialLayout } from "./provider-buttons"
|
|
24
|
+
|
|
25
|
+
export type SignUpProps = {
|
|
26
|
+
className?: string
|
|
27
|
+
socialLayout?: SocialLayout
|
|
28
|
+
socialPosition?: "top" | "bottom"
|
|
29
|
+
variant?: CardProps["variant"]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Render a sign-up form with name, email, password (and optional confirm password) fields, optional social provider buttons, and password visibility controls.
|
|
34
|
+
*
|
|
35
|
+
* The component reflects request state by disabling inputs and showing a pending indicator during sign-up or social sign-in.
|
|
36
|
+
*
|
|
37
|
+
* @param className - Additional CSS classes applied to the outer card container
|
|
38
|
+
* @param socialLayout - Social layout to apply to the provider buttons component
|
|
39
|
+
* @param socialPosition - Position of social provider buttons relative to the form; `"top"` or `"bottom"` (default `"bottom"`)
|
|
40
|
+
* @returns The sign-up form React element
|
|
41
|
+
*/
|
|
42
|
+
export function SignUp({
|
|
43
|
+
className,
|
|
44
|
+
socialLayout,
|
|
45
|
+
socialPosition = "bottom",
|
|
46
|
+
variant,
|
|
47
|
+
...props
|
|
48
|
+
}: SignUpProps & CardProps) {
|
|
49
|
+
const {
|
|
50
|
+
basePaths,
|
|
51
|
+
emailAndPassword,
|
|
52
|
+
localization,
|
|
53
|
+
magicLink,
|
|
54
|
+
redirectTo,
|
|
55
|
+
socialProviders,
|
|
56
|
+
viewPaths,
|
|
57
|
+
navigate
|
|
58
|
+
} = useAuth()
|
|
59
|
+
|
|
60
|
+
const [password, setPassword] = useState("")
|
|
61
|
+
const [confirmPassword, setConfirmPassword] = useState("")
|
|
62
|
+
|
|
63
|
+
const { mutate: signUpEmail, isPending: signUpPending } = useSignUpEmail({
|
|
64
|
+
onError: (error) => {
|
|
65
|
+
setPassword("")
|
|
66
|
+
setConfirmPassword("")
|
|
67
|
+
toast.danger(error.error?.message || error.message)
|
|
68
|
+
},
|
|
69
|
+
onSuccess: () => {
|
|
70
|
+
if (emailAndPassword?.requireEmailVerification) {
|
|
71
|
+
toast.success(localization.auth.verifyYourEmail)
|
|
72
|
+
navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` })
|
|
73
|
+
} else {
|
|
74
|
+
navigate({ to: redirectTo })
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const [socialRedirecting, setSocialRedirecting] = useState(false)
|
|
80
|
+
|
|
81
|
+
const { mutate: signInSocial, isPending: socialPending } = useSignInSocial({
|
|
82
|
+
onError: (error) => toast.danger(error.error?.message || error.message),
|
|
83
|
+
onSuccess: () => {
|
|
84
|
+
setSocialRedirecting(true)
|
|
85
|
+
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
setSocialRedirecting(false)
|
|
88
|
+
}, 5000)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const [isPasswordVisible, setIsPasswordVisible] = useState(false)
|
|
93
|
+
const [isConfirmPasswordVisible, setIsConfirmPasswordVisible] =
|
|
94
|
+
useState(false)
|
|
95
|
+
|
|
96
|
+
const isPending = signUpPending || socialPending || socialRedirecting
|
|
97
|
+
|
|
98
|
+
const handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
|
|
99
|
+
e.preventDefault()
|
|
100
|
+
|
|
101
|
+
const formData = new FormData(e.currentTarget)
|
|
102
|
+
const name = formData.get("name") as string
|
|
103
|
+
const email = formData.get("email") as string
|
|
104
|
+
|
|
105
|
+
if (emailAndPassword?.confirmPassword && password !== confirmPassword) {
|
|
106
|
+
toast.danger(localization.auth.passwordsDoNotMatch)
|
|
107
|
+
setPassword("")
|
|
108
|
+
setConfirmPassword("")
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
signUpEmail({ name, email, password })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const showSeparator = emailAndPassword?.enabled && !!socialProviders?.length
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Card
|
|
119
|
+
className={cn("w-full max-w-sm p-4 md:p-6", className)}
|
|
120
|
+
variant={variant}
|
|
121
|
+
{...props}
|
|
122
|
+
>
|
|
123
|
+
<Card.Header>
|
|
124
|
+
<Card.Title className="text-xl font-semibold mb-1">
|
|
125
|
+
{localization.auth.signUp}
|
|
126
|
+
</Card.Title>
|
|
127
|
+
</Card.Header>
|
|
128
|
+
|
|
129
|
+
<Card.Content className="gap-4">
|
|
130
|
+
{socialPosition === "top" && (
|
|
131
|
+
<>
|
|
132
|
+
{!!socialProviders?.length && (
|
|
133
|
+
<ProviderButtons
|
|
134
|
+
isPending={isPending}
|
|
135
|
+
socialLayout={socialLayout}
|
|
136
|
+
signInSocial={signInSocial}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
|
|
140
|
+
{showSeparator && (
|
|
141
|
+
<FieldSeparator>{localization.auth.or}</FieldSeparator>
|
|
142
|
+
)}
|
|
143
|
+
</>
|
|
144
|
+
)}
|
|
145
|
+
|
|
146
|
+
{emailAndPassword?.enabled && (
|
|
147
|
+
<Form onSubmit={handleSubmit} className="flex flex-col gap-4">
|
|
148
|
+
<TextField
|
|
149
|
+
name="name"
|
|
150
|
+
type="text"
|
|
151
|
+
autoComplete="name"
|
|
152
|
+
isDisabled={isPending}
|
|
153
|
+
>
|
|
154
|
+
<Label>{localization.auth.name}</Label>
|
|
155
|
+
|
|
156
|
+
<Input
|
|
157
|
+
placeholder={localization.auth.namePlaceholder}
|
|
158
|
+
required
|
|
159
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
160
|
+
/>
|
|
161
|
+
|
|
162
|
+
<FieldError />
|
|
163
|
+
</TextField>
|
|
164
|
+
|
|
165
|
+
<TextField
|
|
166
|
+
name="email"
|
|
167
|
+
type="email"
|
|
168
|
+
autoComplete="email"
|
|
169
|
+
isDisabled={isPending}
|
|
170
|
+
>
|
|
171
|
+
<Label>{localization.auth.email}</Label>
|
|
172
|
+
|
|
173
|
+
<Input
|
|
174
|
+
placeholder={localization.auth.emailPlaceholder}
|
|
175
|
+
required
|
|
176
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
177
|
+
/>
|
|
178
|
+
|
|
179
|
+
<FieldError />
|
|
180
|
+
</TextField>
|
|
181
|
+
|
|
182
|
+
<TextField
|
|
183
|
+
minLength={emailAndPassword?.minPasswordLength}
|
|
184
|
+
maxLength={emailAndPassword?.maxPasswordLength}
|
|
185
|
+
name="password"
|
|
186
|
+
autoComplete="new-password"
|
|
187
|
+
isDisabled={isPending}
|
|
188
|
+
value={password}
|
|
189
|
+
onChange={setPassword}
|
|
190
|
+
>
|
|
191
|
+
<Label>{localization.auth.password}</Label>
|
|
192
|
+
|
|
193
|
+
<InputGroup
|
|
194
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
195
|
+
>
|
|
196
|
+
<InputGroup.Input
|
|
197
|
+
placeholder={localization.auth.passwordPlaceholder}
|
|
198
|
+
type={isPasswordVisible ? "text" : "password"}
|
|
199
|
+
name="password"
|
|
200
|
+
required
|
|
201
|
+
/>
|
|
202
|
+
|
|
203
|
+
<InputGroup.Suffix className="px-0">
|
|
204
|
+
<Button
|
|
205
|
+
isIconOnly
|
|
206
|
+
aria-label={
|
|
207
|
+
isPasswordVisible
|
|
208
|
+
? localization.auth.hidePassword
|
|
209
|
+
: localization.auth.showPassword
|
|
210
|
+
}
|
|
211
|
+
size="sm"
|
|
212
|
+
variant="ghost"
|
|
213
|
+
onPress={() => setIsPasswordVisible(!isPasswordVisible)}
|
|
214
|
+
isDisabled={isPending}
|
|
215
|
+
>
|
|
216
|
+
{isPasswordVisible ? <EyeSlash /> : <Eye />}
|
|
217
|
+
</Button>
|
|
218
|
+
</InputGroup.Suffix>
|
|
219
|
+
</InputGroup>
|
|
220
|
+
|
|
221
|
+
<FieldError />
|
|
222
|
+
</TextField>
|
|
223
|
+
|
|
224
|
+
{emailAndPassword?.confirmPassword && (
|
|
225
|
+
<TextField
|
|
226
|
+
minLength={emailAndPassword?.minPasswordLength}
|
|
227
|
+
maxLength={emailAndPassword?.maxPasswordLength}
|
|
228
|
+
name="confirmPassword"
|
|
229
|
+
autoComplete="new-password"
|
|
230
|
+
isDisabled={isPending}
|
|
231
|
+
value={confirmPassword}
|
|
232
|
+
onChange={setConfirmPassword}
|
|
233
|
+
>
|
|
234
|
+
<Label>{localization.auth.confirmPassword}</Label>
|
|
235
|
+
|
|
236
|
+
<InputGroup
|
|
237
|
+
variant={variant === "transparent" ? "primary" : "secondary"}
|
|
238
|
+
>
|
|
239
|
+
<InputGroup.Input
|
|
240
|
+
name="confirmPassword"
|
|
241
|
+
placeholder={localization.auth.confirmPasswordPlaceholder}
|
|
242
|
+
type={isConfirmPasswordVisible ? "text" : "password"}
|
|
243
|
+
required
|
|
244
|
+
/>
|
|
245
|
+
|
|
246
|
+
<InputGroup.Suffix className="px-0">
|
|
247
|
+
<Button
|
|
248
|
+
isIconOnly
|
|
249
|
+
aria-label={
|
|
250
|
+
isConfirmPasswordVisible
|
|
251
|
+
? localization.auth.hidePassword
|
|
252
|
+
: localization.auth.showPassword
|
|
253
|
+
}
|
|
254
|
+
size="sm"
|
|
255
|
+
variant="ghost"
|
|
256
|
+
onPress={() =>
|
|
257
|
+
setIsConfirmPasswordVisible(!isConfirmPasswordVisible)
|
|
258
|
+
}
|
|
259
|
+
isDisabled={isPending}
|
|
260
|
+
>
|
|
261
|
+
{isConfirmPasswordVisible ? <EyeSlash /> : <Eye />}
|
|
262
|
+
</Button>
|
|
263
|
+
</InputGroup.Suffix>
|
|
264
|
+
</InputGroup>
|
|
265
|
+
|
|
266
|
+
<FieldError />
|
|
267
|
+
</TextField>
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
<div className="flex flex-col gap-3">
|
|
271
|
+
<Button type="submit" className="w-full" isPending={isPending}>
|
|
272
|
+
{isPending && <Spinner color="current" size="sm" />}
|
|
273
|
+
|
|
274
|
+
{localization.auth.signUp}
|
|
275
|
+
</Button>
|
|
276
|
+
|
|
277
|
+
{magicLink && (
|
|
278
|
+
<MagicLinkButton view="signUp" isPending={isPending} />
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
</Form>
|
|
282
|
+
)}
|
|
283
|
+
|
|
284
|
+
{socialPosition === "bottom" && (
|
|
285
|
+
<>
|
|
286
|
+
{showSeparator && (
|
|
287
|
+
<FieldSeparator>{localization.auth.or}</FieldSeparator>
|
|
288
|
+
)}
|
|
289
|
+
|
|
290
|
+
{!!socialProviders?.length && (
|
|
291
|
+
<ProviderButtons
|
|
292
|
+
socialLayout={socialLayout}
|
|
293
|
+
signInSocial={signInSocial}
|
|
294
|
+
isPending={isPending}
|
|
295
|
+
/>
|
|
296
|
+
)}
|
|
297
|
+
</>
|
|
298
|
+
)}
|
|
299
|
+
</Card.Content>
|
|
300
|
+
|
|
301
|
+
<Card.Footer className="flex-col">
|
|
302
|
+
<Description className="text-sm">
|
|
303
|
+
{localization.auth.alreadyHaveAnAccount}{" "}
|
|
304
|
+
<Link
|
|
305
|
+
href={`${basePaths.auth}/${viewPaths.auth.signIn}`}
|
|
306
|
+
className="text-accent decoration-accent no-underline hover:underline"
|
|
307
|
+
>
|
|
308
|
+
{localization.auth.signIn}
|
|
309
|
+
</Link>
|
|
310
|
+
</Description>
|
|
311
|
+
</Card.Footer>
|
|
312
|
+
</Card>
|
|
313
|
+
)
|
|
314
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EmailChangedEmail as EmailChangedEmailPrimitive,
|
|
3
|
+
type EmailChangedEmailProps
|
|
4
|
+
} from "@better-auth-ui/react"
|
|
5
|
+
import { cn } from "@heroui/react"
|
|
6
|
+
|
|
7
|
+
export type { EmailChangedEmailProps } from "@better-auth-ui/react"
|
|
8
|
+
|
|
9
|
+
export function EmailChangedEmail({
|
|
10
|
+
colors,
|
|
11
|
+
classNames,
|
|
12
|
+
...props
|
|
13
|
+
}: EmailChangedEmailProps) {
|
|
14
|
+
return (
|
|
15
|
+
<EmailChangedEmailPrimitive
|
|
16
|
+
colors={{
|
|
17
|
+
light: {
|
|
18
|
+
background: "#F5F5F5",
|
|
19
|
+
primary: "#0285F7",
|
|
20
|
+
primaryForeground: "#FCFCFC",
|
|
21
|
+
...colors?.light
|
|
22
|
+
},
|
|
23
|
+
dark: {
|
|
24
|
+
background: "#060607",
|
|
25
|
+
primary: "#0584F6",
|
|
26
|
+
primaryForeground: "#FCFCFC",
|
|
27
|
+
...colors?.dark
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
classNames={{
|
|
31
|
+
...classNames,
|
|
32
|
+
card: cn("border-none rounded-3xl", classNames?.card),
|
|
33
|
+
button: cn("rounded-full", classNames?.button)
|
|
34
|
+
}}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EmailVerificationEmail as EmailVerificationEmailPrimitive,
|
|
3
|
+
type EmailVerificationEmailProps
|
|
4
|
+
} from "@better-auth-ui/react"
|
|
5
|
+
import { cn } from "@heroui/react"
|
|
6
|
+
|
|
7
|
+
export type { EmailVerificationEmailProps } from "@better-auth-ui/react"
|
|
8
|
+
|
|
9
|
+
export function EmailVerificationEmail({
|
|
10
|
+
colors,
|
|
11
|
+
classNames,
|
|
12
|
+
...props
|
|
13
|
+
}: EmailVerificationEmailProps) {
|
|
14
|
+
return (
|
|
15
|
+
<EmailVerificationEmailPrimitive
|
|
16
|
+
colors={{
|
|
17
|
+
light: {
|
|
18
|
+
background: "#F5F5F5",
|
|
19
|
+
primary: "#0285F7",
|
|
20
|
+
primaryForeground: "#FCFCFC",
|
|
21
|
+
...colors?.light
|
|
22
|
+
},
|
|
23
|
+
dark: {
|
|
24
|
+
background: "#060607",
|
|
25
|
+
primary: "#0584F6",
|
|
26
|
+
primaryForeground: "#FCFCFC",
|
|
27
|
+
...colors?.dark
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
classNames={{
|
|
31
|
+
...classNames,
|
|
32
|
+
card: cn("border-none rounded-3xl", classNames?.card),
|
|
33
|
+
button: cn("rounded-full", classNames?.button)
|
|
34
|
+
}}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|