better-auth-ui 3.2.5
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
- package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
- package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
- package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
- package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
- package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
- package/dist/chunk-BDFQSFBU.js +750 -0
- package/dist/chunk-CRAHKL2C.cjs +801 -0
- package/dist/chunk-MJPOA6PK.js +801 -0
- package/dist/chunk-SV64DXGW.cjs +750 -0
- package/dist/index.cjs +12618 -0
- package/dist/index.d.cts +771 -0
- package/dist/index.d.ts +771 -0
- package/dist/index.js +12618 -0
- package/dist/instantdb.cjs +189 -0
- package/dist/instantdb.d.cts +36 -0
- package/dist/instantdb.d.ts +36 -0
- package/dist/instantdb.js +189 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/server.cjs +194 -0
- package/dist/server.d.cts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +194 -0
- package/dist/style.css +1 -0
- package/dist/tanstack.cjs +153 -0
- package/dist/tanstack.d.cts +18 -0
- package/dist/tanstack.d.ts +18 -0
- package/dist/tanstack.js +153 -0
- package/dist/triplit.cjs +201 -0
- package/dist/triplit.d.cts +31 -0
- package/dist/triplit.d.ts +31 -0
- package/dist/triplit.js +201 -0
- package/dist/utils-C5R37WDe.d.cts +3 -0
- package/dist/utils-C5R37WDe.d.ts +3 -0
- package/dist/view-paths-CHSJf5dv.d.cts +645 -0
- package/dist/view-paths-CHSJf5dv.d.ts +645 -0
- package/package.json +156 -0
- package/src/components/account/account-view.tsx +220 -0
- package/src/components/auth/auth-callback.tsx +36 -0
- package/src/components/auth/auth-form.tsx +277 -0
- package/src/components/auth/auth-view.tsx +389 -0
- package/src/components/auth/email-otp-button.tsx +53 -0
- package/src/components/auth/forms/email-otp-form.tsx +288 -0
- package/src/components/auth/forms/forgot-password-form.tsx +168 -0
- package/src/components/auth/forms/magic-link-form.tsx +191 -0
- package/src/components/auth/forms/recover-account-form.tsx +138 -0
- package/src/components/auth/forms/reset-password-form.tsx +215 -0
- package/src/components/auth/forms/sign-in-form.tsx +289 -0
- package/src/components/auth/forms/sign-up-form.tsx +788 -0
- package/src/components/auth/forms/two-factor-form.tsx +372 -0
- package/src/components/auth/magic-link-button.tsx +54 -0
- package/src/components/auth/one-tap.tsx +48 -0
- package/src/components/auth/otp-input-group.tsx +65 -0
- package/src/components/auth/passkey-button.tsx +85 -0
- package/src/components/auth/provider-button.tsx +141 -0
- package/src/components/auth/sign-out.tsx +25 -0
- package/src/components/auth-loading.tsx +21 -0
- package/src/components/captcha/captcha.tsx +79 -0
- package/src/components/captcha/recaptcha-badge.tsx +61 -0
- package/src/components/captcha/recaptcha-v2.tsx +58 -0
- package/src/components/captcha/recaptcha-v3.tsx +73 -0
- package/src/components/email/email-template.tsx +216 -0
- package/src/components/form-error.tsx +27 -0
- package/src/components/organization/accept-invitation-card.tsx +362 -0
- package/src/components/organization/create-organization-dialog.tsx +395 -0
- package/src/components/organization/delete-organization-card.tsx +101 -0
- package/src/components/organization/delete-organization-dialog.tsx +209 -0
- package/src/components/organization/invitation-cell.tsx +156 -0
- package/src/components/organization/invite-member-dialog.tsx +258 -0
- package/src/components/organization/leave-organization-dialog.tsx +150 -0
- package/src/components/organization/member-cell.tsx +187 -0
- package/src/components/organization/organization-cell-view.tsx +122 -0
- package/src/components/organization/organization-cell.tsx +154 -0
- package/src/components/organization/organization-invitations-card.tsx +94 -0
- package/src/components/organization/organization-logo-card.tsx +308 -0
- package/src/components/organization/organization-logo.tsx +120 -0
- package/src/components/organization/organization-members-card.tsx +155 -0
- package/src/components/organization/organization-name-card.tsx +204 -0
- package/src/components/organization/organization-settings-cards.tsx +67 -0
- package/src/components/organization/organization-slug-card.tsx +223 -0
- package/src/components/organization/organization-switcher.tsx +512 -0
- package/src/components/organization/organization-view.tsx +228 -0
- package/src/components/organization/organizations-card.tsx +72 -0
- package/src/components/organization/personal-account-view.tsx +115 -0
- package/src/components/organization/remove-member-dialog.tsx +144 -0
- package/src/components/organization/update-member-role-dialog.tsx +213 -0
- package/src/components/organization/user-invitations-card.tsx +238 -0
- package/src/components/password-input.tsx +56 -0
- package/src/components/provider-icons.tsx +385 -0
- package/src/components/redirect-to-sign-in.tsx +16 -0
- package/src/components/redirect-to-sign-up.tsx +16 -0
- package/src/components/settings/account/account-cell.tsx +158 -0
- package/src/components/settings/account/accounts-card.tsx +75 -0
- package/src/components/settings/account/delete-account-card.tsx +65 -0
- package/src/components/settings/account/delete-account-dialog.tsx +231 -0
- package/src/components/settings/account/update-avatar-card.tsx +198 -0
- package/src/components/settings/account/update-field-card.tsx +282 -0
- package/src/components/settings/account/update-name-card.tsx +39 -0
- package/src/components/settings/account/update-username-card.tsx +42 -0
- package/src/components/settings/account-settings-cards.tsx +123 -0
- package/src/components/settings/api-key/api-key-cell.tsx +108 -0
- package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
- package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
- package/src/components/settings/api-key/api-keys-card.tsx +98 -0
- package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
- package/src/components/settings/passkey/passkey-cell.tsx +113 -0
- package/src/components/settings/passkey/passkeys-card.tsx +111 -0
- package/src/components/settings/providers/provider-cell.tsx +152 -0
- package/src/components/settings/providers/providers-card.tsx +108 -0
- package/src/components/settings/security/change-email-card.tsx +200 -0
- package/src/components/settings/security/change-password-card.tsx +326 -0
- package/src/components/settings/security/session-cell.tsx +120 -0
- package/src/components/settings/security/sessions-card.tsx +58 -0
- package/src/components/settings/security-settings-cards.tsx +111 -0
- package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
- package/src/components/settings/shared/settings-action-button.tsx +51 -0
- package/src/components/settings/shared/settings-card-footer.tsx +94 -0
- package/src/components/settings/shared/settings-card-header.tsx +67 -0
- package/src/components/settings/shared/settings-card.tsx +106 -0
- package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
- package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
- package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
- package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
- package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
- package/src/components/signed-in.tsx +20 -0
- package/src/components/signed-out.tsx +20 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +53 -0
- package/src/components/ui/button.tsx +59 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/dialog.tsx +143 -0
- package/src/components/ui/drawer.tsx +135 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/form.tsx +167 -0
- package/src/components/ui/input-otp.tsx +77 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/select.tsx +185 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/tabs.tsx +66 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/user-avatar.tsx +147 -0
- package/src/components/user-button.tsx +409 -0
- package/src/components/user-view.tsx +138 -0
- package/src/hooks/use-auth-data.ts +184 -0
- package/src/hooks/use-authenticate.ts +62 -0
- package/src/hooks/use-captcha.tsx +138 -0
- package/src/hooks/use-current-organization.ts +59 -0
- package/src/hooks/use-hydrated.ts +13 -0
- package/src/hooks/use-lang.ts +32 -0
- package/src/hooks/use-success-transition.ts +51 -0
- package/src/hooks/use-theme.ts +39 -0
- package/src/index.ts +65 -0
- package/src/instantdb.ts +1 -0
- package/src/lib/auth-data-cache.ts +90 -0
- package/src/lib/auth-ui-provider.tsx +658 -0
- package/src/lib/gravatar-utils.ts +58 -0
- package/src/lib/image-utils.ts +55 -0
- package/src/lib/instantdb/model-names.ts +24 -0
- package/src/lib/instantdb/use-instant-options.ts +98 -0
- package/src/lib/instantdb/use-list-accounts.ts +38 -0
- package/src/lib/instantdb/use-list-sessions.ts +53 -0
- package/src/lib/instantdb/use-session.ts +55 -0
- package/src/lib/organization-refetcher.tsx +56 -0
- package/src/lib/social-providers.ts +144 -0
- package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
- package/src/lib/tanstack/use-tanstack-options.ts +112 -0
- package/src/lib/triplit/model-names.ts +24 -0
- package/src/lib/triplit/use-conditional-query.ts +82 -0
- package/src/lib/triplit/use-list-accounts.ts +31 -0
- package/src/lib/triplit/use-list-sessions.ts +33 -0
- package/src/lib/triplit/use-session.ts +42 -0
- package/src/lib/triplit/use-triplit-hooks.ts +68 -0
- package/src/lib/triplit/use-triplit-token.ts +44 -0
- package/src/lib/utils.ts +105 -0
- package/src/lib/view-paths.ts +55 -0
- package/src/localization/admin-error-codes.ts +20 -0
- package/src/localization/anonymous-error-codes.ts +6 -0
- package/src/localization/api-key-error-codes.ts +32 -0
- package/src/localization/auth-localization.ts +740 -0
- package/src/localization/base-error-codes.ts +27 -0
- package/src/localization/captcha-error-codes.ts +17 -0
- package/src/localization/email-otp-error-codes.ts +7 -0
- package/src/localization/generic-oauth-error-codes.ts +3 -0
- package/src/localization/haveibeenpwned-error-codes.ts +4 -0
- package/src/localization/multi-session-error-codes.ts +3 -0
- package/src/localization/organization-error-codes.ts +57 -0
- package/src/localization/passkey-error-codes.ts +10 -0
- package/src/localization/phone-number-error-codes.ts +10 -0
- package/src/localization/stripe-localization.ts +12 -0
- package/src/localization/two-factor-error-codes.ts +12 -0
- package/src/localization/username-error-codes.ts +9 -0
- package/src/server.ts +4 -0
- package/src/style.css +1 -0
- package/src/tanstack.ts +1 -0
- package/src/triplit.ts +1 -0
- package/src/types/account-options.ts +35 -0
- package/src/types/additional-fields.ts +21 -0
- package/src/types/any-auth-client.ts +6 -0
- package/src/types/api-key.ts +9 -0
- package/src/types/auth-client.ts +37 -0
- package/src/types/auth-hooks.ts +61 -0
- package/src/types/auth-mutators.ts +17 -0
- package/src/types/avatar-options.ts +29 -0
- package/src/types/captcha-options.ts +32 -0
- package/src/types/captcha-provider.ts +6 -0
- package/src/types/credentials-options.ts +32 -0
- package/src/types/delete-user-options.ts +7 -0
- package/src/types/fetch-error.ts +6 -0
- package/src/types/generic-oauth-options.ts +16 -0
- package/src/types/gravatar-options.ts +21 -0
- package/src/types/image.ts +7 -0
- package/src/types/invitation.ts +10 -0
- package/src/types/link.ts +7 -0
- package/src/types/organization-options.ts +106 -0
- package/src/types/password-validation.ts +16 -0
- package/src/types/profile.ts +15 -0
- package/src/types/refetch.ts +1 -0
- package/src/types/render-toast.ts +9 -0
- package/src/types/sign-up-options.ts +7 -0
- package/src/types/social-options.ts +16 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type { BetterFetchError } from "@better-fetch/fetch"
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod"
|
|
5
|
+
import { Loader2, QrCodeIcon, SendIcon } from "lucide-react"
|
|
6
|
+
import { useContext, useEffect, useRef, useState } from "react"
|
|
7
|
+
import { useForm } from "react-hook-form"
|
|
8
|
+
import QRCode from "react-qr-code"
|
|
9
|
+
import * as z from "zod"
|
|
10
|
+
|
|
11
|
+
import { useIsHydrated } from "../../../hooks/use-hydrated"
|
|
12
|
+
import { useOnSuccessTransition } from "../../../hooks/use-success-transition"
|
|
13
|
+
import { AuthUIContext } from "../../../lib/auth-ui-provider"
|
|
14
|
+
import { cn, getLocalizedError, getSearchParam } from "../../../lib/utils"
|
|
15
|
+
import type { AuthLocalization } from "../../../localization/auth-localization"
|
|
16
|
+
import type { User } from "../../../types/auth-client"
|
|
17
|
+
import { Button } from "../../ui/button"
|
|
18
|
+
import { Checkbox } from "../../ui/checkbox"
|
|
19
|
+
import {
|
|
20
|
+
Form,
|
|
21
|
+
FormControl,
|
|
22
|
+
FormField,
|
|
23
|
+
FormItem,
|
|
24
|
+
FormLabel,
|
|
25
|
+
FormMessage
|
|
26
|
+
} from "../../ui/form"
|
|
27
|
+
import { InputOTP } from "../../ui/input-otp"
|
|
28
|
+
import { Label } from "../../ui/label"
|
|
29
|
+
import type { AuthFormClassNames } from "../auth-form"
|
|
30
|
+
import { OTPInputGroup } from "../otp-input-group"
|
|
31
|
+
|
|
32
|
+
export interface TwoFactorFormProps {
|
|
33
|
+
className?: string
|
|
34
|
+
classNames?: AuthFormClassNames
|
|
35
|
+
isSubmitting?: boolean
|
|
36
|
+
localization?: Partial<AuthLocalization>
|
|
37
|
+
otpSeparators?: 0 | 1 | 2
|
|
38
|
+
redirectTo?: string
|
|
39
|
+
setIsSubmitting?: (value: boolean) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function TwoFactorForm({
|
|
43
|
+
className,
|
|
44
|
+
classNames,
|
|
45
|
+
isSubmitting,
|
|
46
|
+
localization,
|
|
47
|
+
otpSeparators = 0,
|
|
48
|
+
redirectTo,
|
|
49
|
+
setIsSubmitting
|
|
50
|
+
}: TwoFactorFormProps) {
|
|
51
|
+
const isHydrated = useIsHydrated()
|
|
52
|
+
const totpURI = isHydrated ? getSearchParam("totpURI") : null
|
|
53
|
+
const initialSendRef = useRef(false)
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
authClient,
|
|
57
|
+
basePath,
|
|
58
|
+
hooks: { useSession },
|
|
59
|
+
localization: contextLocalization,
|
|
60
|
+
twoFactor,
|
|
61
|
+
viewPaths,
|
|
62
|
+
toast,
|
|
63
|
+
Link
|
|
64
|
+
} = useContext(AuthUIContext)
|
|
65
|
+
|
|
66
|
+
localization = { ...contextLocalization, ...localization }
|
|
67
|
+
|
|
68
|
+
const { onSuccess, isPending: transitionPending } = useOnSuccessTransition({
|
|
69
|
+
redirectTo
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const { data: sessionData } = useSession()
|
|
73
|
+
const isTwoFactorEnabled = (sessionData?.user as User)?.twoFactorEnabled
|
|
74
|
+
|
|
75
|
+
const [method, setMethod] = useState<"totp" | "otp" | null>(
|
|
76
|
+
twoFactor?.length === 1 ? twoFactor[0] : null
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
const [isSendingOtp, setIsSendingOtp] = useState(false)
|
|
80
|
+
const [cooldownSeconds, setCooldownSeconds] = useState(0)
|
|
81
|
+
|
|
82
|
+
const formSchema = z.object({
|
|
83
|
+
code: z
|
|
84
|
+
.string()
|
|
85
|
+
.min(1, {
|
|
86
|
+
message: `${localization.ONE_TIME_PASSWORD} ${localization.IS_REQUIRED}`
|
|
87
|
+
})
|
|
88
|
+
.min(6, {
|
|
89
|
+
message: `${localization.ONE_TIME_PASSWORD} ${localization.IS_INVALID}`
|
|
90
|
+
}),
|
|
91
|
+
trustDevice: z.boolean().optional()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const form = useForm({
|
|
95
|
+
resolver: zodResolver(formSchema),
|
|
96
|
+
defaultValues: {
|
|
97
|
+
code: ""
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
isSubmitting =
|
|
102
|
+
isSubmitting || form.formState.isSubmitting || transitionPending
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
setIsSubmitting?.(form.formState.isSubmitting || transitionPending)
|
|
106
|
+
}, [form.formState.isSubmitting, transitionPending, setIsSubmitting])
|
|
107
|
+
|
|
108
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: ignore
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (
|
|
111
|
+
method === "otp" &&
|
|
112
|
+
cooldownSeconds <= 0 &&
|
|
113
|
+
!initialSendRef.current
|
|
114
|
+
) {
|
|
115
|
+
initialSendRef.current = true
|
|
116
|
+
sendOtp()
|
|
117
|
+
}
|
|
118
|
+
}, [method])
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (cooldownSeconds <= 0) return
|
|
122
|
+
|
|
123
|
+
const timer = setTimeout(() => {
|
|
124
|
+
setCooldownSeconds((prev) => prev - 1)
|
|
125
|
+
}, 1000)
|
|
126
|
+
return () => clearTimeout(timer)
|
|
127
|
+
}, [cooldownSeconds])
|
|
128
|
+
|
|
129
|
+
const sendOtp = async () => {
|
|
130
|
+
if (isSendingOtp || cooldownSeconds > 0) return
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
setIsSendingOtp(true)
|
|
134
|
+
await authClient.twoFactor.sendOtp({
|
|
135
|
+
fetchOptions: { throw: true }
|
|
136
|
+
})
|
|
137
|
+
setCooldownSeconds(60)
|
|
138
|
+
} catch (error) {
|
|
139
|
+
toast({
|
|
140
|
+
variant: "error",
|
|
141
|
+
message: getLocalizedError({ error, localization })
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (
|
|
145
|
+
(error as BetterFetchError).error.code ===
|
|
146
|
+
"INVALID_TWO_FACTOR_COOKIE"
|
|
147
|
+
) {
|
|
148
|
+
history.back()
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
initialSendRef.current = false
|
|
153
|
+
setIsSendingOtp(false)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function verifyCode({
|
|
157
|
+
code,
|
|
158
|
+
trustDevice
|
|
159
|
+
}: z.infer<typeof formSchema>) {
|
|
160
|
+
try {
|
|
161
|
+
const verifyMethod =
|
|
162
|
+
method === "totp"
|
|
163
|
+
? authClient.twoFactor.verifyTotp
|
|
164
|
+
: authClient.twoFactor.verifyOtp
|
|
165
|
+
|
|
166
|
+
await verifyMethod({
|
|
167
|
+
code,
|
|
168
|
+
trustDevice,
|
|
169
|
+
fetchOptions: { throw: true }
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
await onSuccess()
|
|
173
|
+
|
|
174
|
+
if (sessionData && !isTwoFactorEnabled) {
|
|
175
|
+
toast({
|
|
176
|
+
variant: "success",
|
|
177
|
+
message: localization?.TWO_FACTOR_ENABLED
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
toast({
|
|
182
|
+
variant: "error",
|
|
183
|
+
message: getLocalizedError({ error, localization })
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
form.reset()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<Form {...form}>
|
|
192
|
+
<form
|
|
193
|
+
onSubmit={form.handleSubmit(verifyCode)}
|
|
194
|
+
className={cn("grid w-full gap-6", className, classNames?.base)}
|
|
195
|
+
>
|
|
196
|
+
{twoFactor?.includes("totp") &&
|
|
197
|
+
totpURI &&
|
|
198
|
+
method === "totp" && (
|
|
199
|
+
<div className="space-y-3">
|
|
200
|
+
<Label className={classNames?.label}>
|
|
201
|
+
{localization.TWO_FACTOR_TOTP_LABEL}
|
|
202
|
+
</Label>
|
|
203
|
+
|
|
204
|
+
<QRCode
|
|
205
|
+
className={cn(
|
|
206
|
+
"border shadow-xs",
|
|
207
|
+
classNames?.qrCode
|
|
208
|
+
)}
|
|
209
|
+
value={totpURI}
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
{method !== null && (
|
|
215
|
+
<>
|
|
216
|
+
<FormField
|
|
217
|
+
control={form.control}
|
|
218
|
+
name="code"
|
|
219
|
+
render={({ field }) => (
|
|
220
|
+
<FormItem>
|
|
221
|
+
<div className="flex items-center justify-between">
|
|
222
|
+
<FormLabel
|
|
223
|
+
className={classNames?.label}
|
|
224
|
+
>
|
|
225
|
+
{localization.ONE_TIME_PASSWORD}
|
|
226
|
+
</FormLabel>
|
|
227
|
+
|
|
228
|
+
<Link
|
|
229
|
+
className={cn(
|
|
230
|
+
"text-sm hover:underline",
|
|
231
|
+
classNames?.forgotPasswordLink
|
|
232
|
+
)}
|
|
233
|
+
href={`${basePath}/${viewPaths.RECOVER_ACCOUNT}${isHydrated ? window.location.search : ""}`}
|
|
234
|
+
>
|
|
235
|
+
{localization.FORGOT_AUTHENTICATOR}
|
|
236
|
+
</Link>
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
<FormControl>
|
|
240
|
+
<InputOTP
|
|
241
|
+
{...field}
|
|
242
|
+
maxLength={6}
|
|
243
|
+
onChange={(value) => {
|
|
244
|
+
field.onChange(value)
|
|
245
|
+
|
|
246
|
+
if (value.length === 6) {
|
|
247
|
+
form.handleSubmit(
|
|
248
|
+
verifyCode
|
|
249
|
+
)()
|
|
250
|
+
}
|
|
251
|
+
}}
|
|
252
|
+
containerClassName={
|
|
253
|
+
classNames?.otpInputContainer
|
|
254
|
+
}
|
|
255
|
+
className={classNames?.otpInput}
|
|
256
|
+
disabled={isSubmitting}
|
|
257
|
+
>
|
|
258
|
+
<OTPInputGroup
|
|
259
|
+
otpSeparators={otpSeparators}
|
|
260
|
+
/>
|
|
261
|
+
</InputOTP>
|
|
262
|
+
</FormControl>
|
|
263
|
+
|
|
264
|
+
<FormMessage
|
|
265
|
+
className={classNames?.error}
|
|
266
|
+
/>
|
|
267
|
+
</FormItem>
|
|
268
|
+
)}
|
|
269
|
+
/>
|
|
270
|
+
|
|
271
|
+
<FormField
|
|
272
|
+
control={form.control}
|
|
273
|
+
name="trustDevice"
|
|
274
|
+
render={({ field }) => (
|
|
275
|
+
<FormItem className="flex">
|
|
276
|
+
<FormControl>
|
|
277
|
+
<Checkbox
|
|
278
|
+
checked={field.value}
|
|
279
|
+
onCheckedChange={field.onChange}
|
|
280
|
+
disabled={isSubmitting}
|
|
281
|
+
className={classNames?.checkbox}
|
|
282
|
+
/>
|
|
283
|
+
</FormControl>
|
|
284
|
+
|
|
285
|
+
<FormLabel className={classNames?.label}>
|
|
286
|
+
{localization.TRUST_DEVICE}
|
|
287
|
+
</FormLabel>
|
|
288
|
+
</FormItem>
|
|
289
|
+
)}
|
|
290
|
+
/>
|
|
291
|
+
</>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
<div className="grid gap-4">
|
|
295
|
+
{method !== null && (
|
|
296
|
+
<Button
|
|
297
|
+
type="submit"
|
|
298
|
+
disabled={isSubmitting}
|
|
299
|
+
className={cn(
|
|
300
|
+
classNames?.button,
|
|
301
|
+
classNames?.primaryButton
|
|
302
|
+
)}
|
|
303
|
+
>
|
|
304
|
+
{isSubmitting && (
|
|
305
|
+
<Loader2 className="animate-spin" />
|
|
306
|
+
)}
|
|
307
|
+
{localization.TWO_FACTOR_ACTION}
|
|
308
|
+
</Button>
|
|
309
|
+
)}
|
|
310
|
+
|
|
311
|
+
{method === "otp" && twoFactor?.includes("otp") && (
|
|
312
|
+
<Button
|
|
313
|
+
type="button"
|
|
314
|
+
variant="outline"
|
|
315
|
+
onClick={sendOtp}
|
|
316
|
+
disabled={
|
|
317
|
+
cooldownSeconds > 0 ||
|
|
318
|
+
isSendingOtp ||
|
|
319
|
+
isSubmitting
|
|
320
|
+
}
|
|
321
|
+
className={cn(
|
|
322
|
+
classNames?.button,
|
|
323
|
+
classNames?.outlineButton
|
|
324
|
+
)}
|
|
325
|
+
>
|
|
326
|
+
{isSendingOtp ? (
|
|
327
|
+
<Loader2 className="animate-spin" />
|
|
328
|
+
) : (
|
|
329
|
+
<SendIcon className={classNames?.icon} />
|
|
330
|
+
)}
|
|
331
|
+
|
|
332
|
+
{localization.RESEND_CODE}
|
|
333
|
+
{cooldownSeconds > 0 && ` (${cooldownSeconds})`}
|
|
334
|
+
</Button>
|
|
335
|
+
)}
|
|
336
|
+
|
|
337
|
+
{method !== "otp" && twoFactor?.includes("otp") && (
|
|
338
|
+
<Button
|
|
339
|
+
type="button"
|
|
340
|
+
variant="secondary"
|
|
341
|
+
className={cn(
|
|
342
|
+
classNames?.button,
|
|
343
|
+
classNames?.secondaryButton
|
|
344
|
+
)}
|
|
345
|
+
onClick={() => setMethod("otp")}
|
|
346
|
+
disabled={isSubmitting}
|
|
347
|
+
>
|
|
348
|
+
<SendIcon className={classNames?.icon} />
|
|
349
|
+
{localization.SEND_VERIFICATION_CODE}
|
|
350
|
+
</Button>
|
|
351
|
+
)}
|
|
352
|
+
|
|
353
|
+
{method !== "totp" && twoFactor?.includes("totp") && (
|
|
354
|
+
<Button
|
|
355
|
+
type="button"
|
|
356
|
+
variant="secondary"
|
|
357
|
+
className={cn(
|
|
358
|
+
classNames?.button,
|
|
359
|
+
classNames?.secondaryButton
|
|
360
|
+
)}
|
|
361
|
+
onClick={() => setMethod("totp")}
|
|
362
|
+
disabled={isSubmitting}
|
|
363
|
+
>
|
|
364
|
+
<QrCodeIcon className={classNames?.icon} />
|
|
365
|
+
{localization.CONTINUE_WITH_AUTHENTICATOR}
|
|
366
|
+
</Button>
|
|
367
|
+
)}
|
|
368
|
+
</div>
|
|
369
|
+
</form>
|
|
370
|
+
</Form>
|
|
371
|
+
)
|
|
372
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LockIcon, MailIcon } from "lucide-react"
|
|
2
|
+
import { useContext } from "react"
|
|
3
|
+
|
|
4
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import type { AuthViewPath } from "../../lib/view-paths"
|
|
7
|
+
import type { AuthLocalization } from "../../localization/auth-localization"
|
|
8
|
+
import { Button } from "../ui/button"
|
|
9
|
+
import type { AuthViewClassNames } from "./auth-view"
|
|
10
|
+
|
|
11
|
+
interface MagicLinkButtonProps {
|
|
12
|
+
classNames?: AuthViewClassNames
|
|
13
|
+
isSubmitting?: boolean
|
|
14
|
+
localization: Partial<AuthLocalization>
|
|
15
|
+
view: AuthViewPath
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function MagicLinkButton({
|
|
19
|
+
classNames,
|
|
20
|
+
isSubmitting,
|
|
21
|
+
localization,
|
|
22
|
+
view
|
|
23
|
+
}: MagicLinkButtonProps) {
|
|
24
|
+
const { viewPaths, navigate, basePath, credentials } =
|
|
25
|
+
useContext(AuthUIContext)
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Button
|
|
29
|
+
className={cn(
|
|
30
|
+
"w-full",
|
|
31
|
+
classNames?.form?.button,
|
|
32
|
+
classNames?.form?.secondaryButton
|
|
33
|
+
)}
|
|
34
|
+
disabled={isSubmitting}
|
|
35
|
+
type="button"
|
|
36
|
+
variant="secondary"
|
|
37
|
+
onClick={() =>
|
|
38
|
+
navigate(
|
|
39
|
+
`${basePath}/${view === "MAGIC_LINK" || !credentials ? viewPaths.SIGN_IN : viewPaths.MAGIC_LINK}${window.location.search}`
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
>
|
|
43
|
+
{view === "MAGIC_LINK" ? (
|
|
44
|
+
<LockIcon className={classNames?.form?.icon} />
|
|
45
|
+
) : (
|
|
46
|
+
<MailIcon className={classNames?.form?.icon} />
|
|
47
|
+
)}
|
|
48
|
+
{localization.SIGN_IN_WITH}{" "}
|
|
49
|
+
{view === "MAGIC_LINK"
|
|
50
|
+
? localization.PASSWORD
|
|
51
|
+
: localization.MAGIC_LINK}
|
|
52
|
+
</Button>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useContext, useEffect, useMemo, useRef } from "react"
|
|
2
|
+
|
|
3
|
+
import { useOnSuccessTransition } from "../../hooks/use-success-transition"
|
|
4
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
5
|
+
import { getLocalizedError } from "../../lib/utils"
|
|
6
|
+
import type { AuthLocalization } from "../../localization/auth-localization"
|
|
7
|
+
|
|
8
|
+
interface OneTapProps {
|
|
9
|
+
localization: Partial<AuthLocalization>
|
|
10
|
+
redirectTo?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function OneTap({ localization, redirectTo }: OneTapProps) {
|
|
14
|
+
const {
|
|
15
|
+
authClient,
|
|
16
|
+
localization: contextLocalization,
|
|
17
|
+
toast
|
|
18
|
+
} = useContext(AuthUIContext)
|
|
19
|
+
const oneTapFetched = useRef(false)
|
|
20
|
+
|
|
21
|
+
localization = useMemo(
|
|
22
|
+
() => ({ ...contextLocalization, ...localization }),
|
|
23
|
+
[contextLocalization, localization]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const { onSuccess } = useOnSuccessTransition({ redirectTo })
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (oneTapFetched.current) return
|
|
30
|
+
oneTapFetched.current = true
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
authClient.oneTap({
|
|
34
|
+
fetchOptions: {
|
|
35
|
+
throw: true,
|
|
36
|
+
onSuccess
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
} catch (error) {
|
|
40
|
+
toast({
|
|
41
|
+
variant: "error",
|
|
42
|
+
message: getLocalizedError({ error, localization })
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
}, [authClient, localization, onSuccess, toast])
|
|
46
|
+
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "../ui/input-otp"
|
|
4
|
+
|
|
5
|
+
export function OTPInputGroup({
|
|
6
|
+
otpSeparators = 0
|
|
7
|
+
}: {
|
|
8
|
+
otpSeparators?: 0 | 1 | 2
|
|
9
|
+
}) {
|
|
10
|
+
if (otpSeparators === 0) {
|
|
11
|
+
return (
|
|
12
|
+
<InputOTPGroup>
|
|
13
|
+
<InputOTPSlot index={0} />
|
|
14
|
+
<InputOTPSlot index={1} />
|
|
15
|
+
<InputOTPSlot index={2} />
|
|
16
|
+
<InputOTPSlot index={3} />
|
|
17
|
+
<InputOTPSlot index={4} />
|
|
18
|
+
<InputOTPSlot index={5} />
|
|
19
|
+
</InputOTPGroup>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (otpSeparators === 1) {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<InputOTPGroup>
|
|
27
|
+
<InputOTPSlot index={0} />
|
|
28
|
+
<InputOTPSlot index={1} />
|
|
29
|
+
<InputOTPSlot index={2} />
|
|
30
|
+
</InputOTPGroup>
|
|
31
|
+
|
|
32
|
+
<InputOTPSeparator />
|
|
33
|
+
|
|
34
|
+
<InputOTPGroup>
|
|
35
|
+
<InputOTPSlot index={3} />
|
|
36
|
+
<InputOTPSlot index={4} />
|
|
37
|
+
<InputOTPSlot index={5} />
|
|
38
|
+
</InputOTPGroup>
|
|
39
|
+
</>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<InputOTPGroup>
|
|
46
|
+
<InputOTPSlot index={0} />
|
|
47
|
+
<InputOTPSlot index={1} />
|
|
48
|
+
</InputOTPGroup>
|
|
49
|
+
|
|
50
|
+
<InputOTPSeparator />
|
|
51
|
+
|
|
52
|
+
<InputOTPGroup>
|
|
53
|
+
<InputOTPSlot index={2} />
|
|
54
|
+
<InputOTPSlot index={3} />
|
|
55
|
+
</InputOTPGroup>
|
|
56
|
+
|
|
57
|
+
<InputOTPSeparator />
|
|
58
|
+
|
|
59
|
+
<InputOTPGroup>
|
|
60
|
+
<InputOTPSlot index={4} />
|
|
61
|
+
<InputOTPSlot index={5} />
|
|
62
|
+
</InputOTPGroup>
|
|
63
|
+
</>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FingerprintIcon } from "lucide-react"
|
|
2
|
+
import { useContext } from "react"
|
|
3
|
+
|
|
4
|
+
import { useOnSuccessTransition } from "../../hooks/use-success-transition"
|
|
5
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
6
|
+
import { cn, getLocalizedError } from "../../lib/utils"
|
|
7
|
+
import type { AuthLocalization } from "../../localization/auth-localization"
|
|
8
|
+
import { Button } from "../ui/button"
|
|
9
|
+
import type { AuthViewClassNames } from "./auth-view"
|
|
10
|
+
|
|
11
|
+
interface PasskeyButtonProps {
|
|
12
|
+
classNames?: AuthViewClassNames
|
|
13
|
+
isSubmitting?: boolean
|
|
14
|
+
localization: Partial<AuthLocalization>
|
|
15
|
+
redirectTo?: string
|
|
16
|
+
setIsSubmitting?: (isSubmitting: boolean) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function PasskeyButton({
|
|
20
|
+
classNames,
|
|
21
|
+
isSubmitting,
|
|
22
|
+
localization,
|
|
23
|
+
redirectTo,
|
|
24
|
+
setIsSubmitting
|
|
25
|
+
}: PasskeyButtonProps) {
|
|
26
|
+
const {
|
|
27
|
+
authClient,
|
|
28
|
+
localization: contextLocalization,
|
|
29
|
+
toast
|
|
30
|
+
} = useContext(AuthUIContext)
|
|
31
|
+
|
|
32
|
+
localization = { ...contextLocalization, ...localization }
|
|
33
|
+
|
|
34
|
+
const { onSuccess } = useOnSuccessTransition({ redirectTo })
|
|
35
|
+
|
|
36
|
+
const signInPassKey = async () => {
|
|
37
|
+
setIsSubmitting?.(true)
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const response = await authClient.signIn.passkey({
|
|
41
|
+
fetchOptions: { throw: true }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (response?.error) {
|
|
45
|
+
toast({
|
|
46
|
+
variant: "error",
|
|
47
|
+
message: getLocalizedError({
|
|
48
|
+
error: response.error,
|
|
49
|
+
localization
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
setIsSubmitting?.(false)
|
|
54
|
+
} else {
|
|
55
|
+
onSuccess()
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
toast({
|
|
59
|
+
variant: "error",
|
|
60
|
+
message: getLocalizedError({ error, localization })
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
setIsSubmitting?.(false)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Button
|
|
69
|
+
className={cn(
|
|
70
|
+
"w-full",
|
|
71
|
+
classNames?.form?.button,
|
|
72
|
+
classNames?.form?.secondaryButton
|
|
73
|
+
)}
|
|
74
|
+
disabled={isSubmitting}
|
|
75
|
+
formNoValidate
|
|
76
|
+
name="passkey"
|
|
77
|
+
value="true"
|
|
78
|
+
variant="secondary"
|
|
79
|
+
onClick={signInPassKey}
|
|
80
|
+
>
|
|
81
|
+
<FingerprintIcon />
|
|
82
|
+
{localization.SIGN_IN_WITH} {localization.PASSKEY}
|
|
83
|
+
</Button>
|
|
84
|
+
)
|
|
85
|
+
}
|