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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
  4. package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
  5. package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
  6. package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
  7. package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
  8. package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
  9. package/dist/chunk-BDFQSFBU.js +750 -0
  10. package/dist/chunk-CRAHKL2C.cjs +801 -0
  11. package/dist/chunk-MJPOA6PK.js +801 -0
  12. package/dist/chunk-SV64DXGW.cjs +750 -0
  13. package/dist/index.cjs +12618 -0
  14. package/dist/index.d.cts +771 -0
  15. package/dist/index.d.ts +771 -0
  16. package/dist/index.js +12618 -0
  17. package/dist/instantdb.cjs +189 -0
  18. package/dist/instantdb.d.cts +36 -0
  19. package/dist/instantdb.d.ts +36 -0
  20. package/dist/instantdb.js +189 -0
  21. package/dist/metafile-cjs.json +1 -0
  22. package/dist/metafile-esm.json +1 -0
  23. package/dist/server.cjs +194 -0
  24. package/dist/server.d.cts +35 -0
  25. package/dist/server.d.ts +35 -0
  26. package/dist/server.js +194 -0
  27. package/dist/style.css +1 -0
  28. package/dist/tanstack.cjs +153 -0
  29. package/dist/tanstack.d.cts +18 -0
  30. package/dist/tanstack.d.ts +18 -0
  31. package/dist/tanstack.js +153 -0
  32. package/dist/triplit.cjs +201 -0
  33. package/dist/triplit.d.cts +31 -0
  34. package/dist/triplit.d.ts +31 -0
  35. package/dist/triplit.js +201 -0
  36. package/dist/utils-C5R37WDe.d.cts +3 -0
  37. package/dist/utils-C5R37WDe.d.ts +3 -0
  38. package/dist/view-paths-CHSJf5dv.d.cts +645 -0
  39. package/dist/view-paths-CHSJf5dv.d.ts +645 -0
  40. package/package.json +156 -0
  41. package/src/components/account/account-view.tsx +220 -0
  42. package/src/components/auth/auth-callback.tsx +36 -0
  43. package/src/components/auth/auth-form.tsx +277 -0
  44. package/src/components/auth/auth-view.tsx +389 -0
  45. package/src/components/auth/email-otp-button.tsx +53 -0
  46. package/src/components/auth/forms/email-otp-form.tsx +288 -0
  47. package/src/components/auth/forms/forgot-password-form.tsx +168 -0
  48. package/src/components/auth/forms/magic-link-form.tsx +191 -0
  49. package/src/components/auth/forms/recover-account-form.tsx +138 -0
  50. package/src/components/auth/forms/reset-password-form.tsx +215 -0
  51. package/src/components/auth/forms/sign-in-form.tsx +289 -0
  52. package/src/components/auth/forms/sign-up-form.tsx +788 -0
  53. package/src/components/auth/forms/two-factor-form.tsx +372 -0
  54. package/src/components/auth/magic-link-button.tsx +54 -0
  55. package/src/components/auth/one-tap.tsx +48 -0
  56. package/src/components/auth/otp-input-group.tsx +65 -0
  57. package/src/components/auth/passkey-button.tsx +85 -0
  58. package/src/components/auth/provider-button.tsx +141 -0
  59. package/src/components/auth/sign-out.tsx +25 -0
  60. package/src/components/auth-loading.tsx +21 -0
  61. package/src/components/captcha/captcha.tsx +79 -0
  62. package/src/components/captcha/recaptcha-badge.tsx +61 -0
  63. package/src/components/captcha/recaptcha-v2.tsx +58 -0
  64. package/src/components/captcha/recaptcha-v3.tsx +73 -0
  65. package/src/components/email/email-template.tsx +216 -0
  66. package/src/components/form-error.tsx +27 -0
  67. package/src/components/organization/accept-invitation-card.tsx +362 -0
  68. package/src/components/organization/create-organization-dialog.tsx +395 -0
  69. package/src/components/organization/delete-organization-card.tsx +101 -0
  70. package/src/components/organization/delete-organization-dialog.tsx +209 -0
  71. package/src/components/organization/invitation-cell.tsx +156 -0
  72. package/src/components/organization/invite-member-dialog.tsx +258 -0
  73. package/src/components/organization/leave-organization-dialog.tsx +150 -0
  74. package/src/components/organization/member-cell.tsx +187 -0
  75. package/src/components/organization/organization-cell-view.tsx +122 -0
  76. package/src/components/organization/organization-cell.tsx +154 -0
  77. package/src/components/organization/organization-invitations-card.tsx +94 -0
  78. package/src/components/organization/organization-logo-card.tsx +308 -0
  79. package/src/components/organization/organization-logo.tsx +120 -0
  80. package/src/components/organization/organization-members-card.tsx +155 -0
  81. package/src/components/organization/organization-name-card.tsx +204 -0
  82. package/src/components/organization/organization-settings-cards.tsx +67 -0
  83. package/src/components/organization/organization-slug-card.tsx +223 -0
  84. package/src/components/organization/organization-switcher.tsx +512 -0
  85. package/src/components/organization/organization-view.tsx +228 -0
  86. package/src/components/organization/organizations-card.tsx +72 -0
  87. package/src/components/organization/personal-account-view.tsx +115 -0
  88. package/src/components/organization/remove-member-dialog.tsx +144 -0
  89. package/src/components/organization/update-member-role-dialog.tsx +213 -0
  90. package/src/components/organization/user-invitations-card.tsx +238 -0
  91. package/src/components/password-input.tsx +56 -0
  92. package/src/components/provider-icons.tsx +385 -0
  93. package/src/components/redirect-to-sign-in.tsx +16 -0
  94. package/src/components/redirect-to-sign-up.tsx +16 -0
  95. package/src/components/settings/account/account-cell.tsx +158 -0
  96. package/src/components/settings/account/accounts-card.tsx +75 -0
  97. package/src/components/settings/account/delete-account-card.tsx +65 -0
  98. package/src/components/settings/account/delete-account-dialog.tsx +231 -0
  99. package/src/components/settings/account/update-avatar-card.tsx +198 -0
  100. package/src/components/settings/account/update-field-card.tsx +282 -0
  101. package/src/components/settings/account/update-name-card.tsx +39 -0
  102. package/src/components/settings/account/update-username-card.tsx +42 -0
  103. package/src/components/settings/account-settings-cards.tsx +123 -0
  104. package/src/components/settings/api-key/api-key-cell.tsx +108 -0
  105. package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
  106. package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
  107. package/src/components/settings/api-key/api-keys-card.tsx +98 -0
  108. package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
  109. package/src/components/settings/passkey/passkey-cell.tsx +113 -0
  110. package/src/components/settings/passkey/passkeys-card.tsx +111 -0
  111. package/src/components/settings/providers/provider-cell.tsx +152 -0
  112. package/src/components/settings/providers/providers-card.tsx +108 -0
  113. package/src/components/settings/security/change-email-card.tsx +200 -0
  114. package/src/components/settings/security/change-password-card.tsx +326 -0
  115. package/src/components/settings/security/session-cell.tsx +120 -0
  116. package/src/components/settings/security/sessions-card.tsx +58 -0
  117. package/src/components/settings/security-settings-cards.tsx +111 -0
  118. package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
  119. package/src/components/settings/shared/settings-action-button.tsx +51 -0
  120. package/src/components/settings/shared/settings-card-footer.tsx +94 -0
  121. package/src/components/settings/shared/settings-card-header.tsx +67 -0
  122. package/src/components/settings/shared/settings-card.tsx +106 -0
  123. package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
  124. package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
  125. package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
  126. package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
  127. package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
  128. package/src/components/signed-in.tsx +20 -0
  129. package/src/components/signed-out.tsx +20 -0
  130. package/src/components/ui/alert.tsx +66 -0
  131. package/src/components/ui/avatar.tsx +53 -0
  132. package/src/components/ui/button.tsx +59 -0
  133. package/src/components/ui/card.tsx +92 -0
  134. package/src/components/ui/checkbox.tsx +32 -0
  135. package/src/components/ui/dialog.tsx +143 -0
  136. package/src/components/ui/drawer.tsx +135 -0
  137. package/src/components/ui/dropdown-menu.tsx +257 -0
  138. package/src/components/ui/form.tsx +167 -0
  139. package/src/components/ui/input-otp.tsx +77 -0
  140. package/src/components/ui/input.tsx +21 -0
  141. package/src/components/ui/label.tsx +24 -0
  142. package/src/components/ui/select.tsx +185 -0
  143. package/src/components/ui/separator.tsx +28 -0
  144. package/src/components/ui/skeleton.tsx +13 -0
  145. package/src/components/ui/tabs.tsx +66 -0
  146. package/src/components/ui/textarea.tsx +18 -0
  147. package/src/components/user-avatar.tsx +147 -0
  148. package/src/components/user-button.tsx +409 -0
  149. package/src/components/user-view.tsx +138 -0
  150. package/src/hooks/use-auth-data.ts +184 -0
  151. package/src/hooks/use-authenticate.ts +62 -0
  152. package/src/hooks/use-captcha.tsx +138 -0
  153. package/src/hooks/use-current-organization.ts +59 -0
  154. package/src/hooks/use-hydrated.ts +13 -0
  155. package/src/hooks/use-lang.ts +32 -0
  156. package/src/hooks/use-success-transition.ts +51 -0
  157. package/src/hooks/use-theme.ts +39 -0
  158. package/src/index.ts +65 -0
  159. package/src/instantdb.ts +1 -0
  160. package/src/lib/auth-data-cache.ts +90 -0
  161. package/src/lib/auth-ui-provider.tsx +658 -0
  162. package/src/lib/gravatar-utils.ts +58 -0
  163. package/src/lib/image-utils.ts +55 -0
  164. package/src/lib/instantdb/model-names.ts +24 -0
  165. package/src/lib/instantdb/use-instant-options.ts +98 -0
  166. package/src/lib/instantdb/use-list-accounts.ts +38 -0
  167. package/src/lib/instantdb/use-list-sessions.ts +53 -0
  168. package/src/lib/instantdb/use-session.ts +55 -0
  169. package/src/lib/organization-refetcher.tsx +56 -0
  170. package/src/lib/social-providers.ts +144 -0
  171. package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
  172. package/src/lib/tanstack/use-tanstack-options.ts +112 -0
  173. package/src/lib/triplit/model-names.ts +24 -0
  174. package/src/lib/triplit/use-conditional-query.ts +82 -0
  175. package/src/lib/triplit/use-list-accounts.ts +31 -0
  176. package/src/lib/triplit/use-list-sessions.ts +33 -0
  177. package/src/lib/triplit/use-session.ts +42 -0
  178. package/src/lib/triplit/use-triplit-hooks.ts +68 -0
  179. package/src/lib/triplit/use-triplit-token.ts +44 -0
  180. package/src/lib/utils.ts +105 -0
  181. package/src/lib/view-paths.ts +55 -0
  182. package/src/localization/admin-error-codes.ts +20 -0
  183. package/src/localization/anonymous-error-codes.ts +6 -0
  184. package/src/localization/api-key-error-codes.ts +32 -0
  185. package/src/localization/auth-localization.ts +740 -0
  186. package/src/localization/base-error-codes.ts +27 -0
  187. package/src/localization/captcha-error-codes.ts +17 -0
  188. package/src/localization/email-otp-error-codes.ts +7 -0
  189. package/src/localization/generic-oauth-error-codes.ts +3 -0
  190. package/src/localization/haveibeenpwned-error-codes.ts +4 -0
  191. package/src/localization/multi-session-error-codes.ts +3 -0
  192. package/src/localization/organization-error-codes.ts +57 -0
  193. package/src/localization/passkey-error-codes.ts +10 -0
  194. package/src/localization/phone-number-error-codes.ts +10 -0
  195. package/src/localization/stripe-localization.ts +12 -0
  196. package/src/localization/two-factor-error-codes.ts +12 -0
  197. package/src/localization/username-error-codes.ts +9 -0
  198. package/src/server.ts +4 -0
  199. package/src/style.css +1 -0
  200. package/src/tanstack.ts +1 -0
  201. package/src/triplit.ts +1 -0
  202. package/src/types/account-options.ts +35 -0
  203. package/src/types/additional-fields.ts +21 -0
  204. package/src/types/any-auth-client.ts +6 -0
  205. package/src/types/api-key.ts +9 -0
  206. package/src/types/auth-client.ts +37 -0
  207. package/src/types/auth-hooks.ts +61 -0
  208. package/src/types/auth-mutators.ts +17 -0
  209. package/src/types/avatar-options.ts +29 -0
  210. package/src/types/captcha-options.ts +32 -0
  211. package/src/types/captcha-provider.ts +6 -0
  212. package/src/types/credentials-options.ts +32 -0
  213. package/src/types/delete-user-options.ts +7 -0
  214. package/src/types/fetch-error.ts +6 -0
  215. package/src/types/generic-oauth-options.ts +16 -0
  216. package/src/types/gravatar-options.ts +21 -0
  217. package/src/types/image.ts +7 -0
  218. package/src/types/invitation.ts +10 -0
  219. package/src/types/link.ts +7 -0
  220. package/src/types/organization-options.ts +106 -0
  221. package/src/types/password-validation.ts +16 -0
  222. package/src/types/profile.ts +15 -0
  223. package/src/types/refetch.ts +1 -0
  224. package/src/types/render-toast.ts +9 -0
  225. package/src/types/sign-up-options.ts +7 -0
  226. package/src/types/social-options.ts +16 -0
@@ -0,0 +1,389 @@
1
+ "use client"
2
+
3
+ import { ArrowLeftIcon } from "lucide-react"
4
+ import { type ReactNode, useContext, useEffect, useState } from "react"
5
+ import { useIsHydrated } from "../../hooks/use-hydrated"
6
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
7
+ import { socialProviders } from "../../lib/social-providers"
8
+ import { cn, getViewByPath } from "../../lib/utils"
9
+ import type { AuthViewPaths } from "../../lib/view-paths"
10
+ import type { AuthLocalization } from "../../localization/auth-localization"
11
+ import { AcceptInvitationCard } from "../organization/accept-invitation-card"
12
+ import { Button } from "../ui/button"
13
+ import {
14
+ Card,
15
+ CardContent,
16
+ CardDescription,
17
+ CardFooter,
18
+ CardHeader,
19
+ CardTitle
20
+ } from "../ui/card"
21
+ import { Separator } from "../ui/separator"
22
+ import { AuthCallback } from "./auth-callback"
23
+ import { AuthForm, type AuthFormClassNames } from "./auth-form"
24
+ import { EmailOTPButton } from "./email-otp-button"
25
+ import { MagicLinkButton } from "./magic-link-button"
26
+ import { OneTap } from "./one-tap"
27
+ import { PasskeyButton } from "./passkey-button"
28
+ import { ProviderButton } from "./provider-button"
29
+ import { SignOut } from "./sign-out"
30
+
31
+ export type AuthViewClassNames = {
32
+ base?: string
33
+ content?: string
34
+ description?: string
35
+ footer?: string
36
+ footerLink?: string
37
+ continueWith?: string
38
+ form?: AuthFormClassNames
39
+ header?: string
40
+ separator?: string
41
+ title?: string
42
+ }
43
+
44
+ export interface AuthViewProps {
45
+ className?: string
46
+ classNames?: AuthViewClassNames
47
+ callbackURL?: string
48
+ cardHeader?: ReactNode
49
+ localization?: AuthLocalization
50
+ path?: string
51
+ pathname?: string
52
+ redirectTo?: string
53
+ socialLayout?: "auto" | "horizontal" | "grid" | "vertical"
54
+ view?: keyof AuthViewPaths
55
+ otpSeparators?: 0 | 1 | 2
56
+ }
57
+
58
+ export function AuthView({
59
+ className,
60
+ classNames,
61
+ callbackURL,
62
+ cardHeader,
63
+ localization,
64
+ path: pathProp,
65
+ pathname,
66
+ redirectTo,
67
+ socialLayout: socialLayoutProp = "auto",
68
+ view: viewProp,
69
+ otpSeparators = 0
70
+ }: AuthViewProps) {
71
+ const isHydrated = useIsHydrated()
72
+ const {
73
+ basePath,
74
+ credentials,
75
+ localization: contextLocalization,
76
+ magicLink,
77
+ emailOTP,
78
+ oneTap,
79
+ passkey,
80
+ signUp,
81
+ social,
82
+ genericOAuth,
83
+ viewPaths,
84
+ Link
85
+ } = useContext(AuthUIContext)
86
+
87
+ localization = { ...contextLocalization, ...localization }
88
+
89
+ let socialLayout = socialLayoutProp
90
+ if (socialLayout === "auto") {
91
+ socialLayout = !credentials
92
+ ? "vertical"
93
+ : social?.providers && social.providers.length > 2
94
+ ? "horizontal"
95
+ : "vertical"
96
+ }
97
+
98
+ const path = pathProp ?? pathname?.split("/").pop()
99
+
100
+ const view = viewProp || getViewByPath(viewPaths!, path) || "SIGN_IN"
101
+
102
+ const [isSubmitting, setIsSubmitting] = useState(false)
103
+
104
+ useEffect(() => {
105
+ const handlePageHide = () => setIsSubmitting(false)
106
+ window.addEventListener("pagehide", handlePageHide)
107
+ return () => {
108
+ setIsSubmitting(false)
109
+ window.removeEventListener("pagehide", handlePageHide)
110
+ }
111
+ }, [])
112
+
113
+ if (view === "CALLBACK") return <AuthCallback redirectTo={redirectTo} />
114
+ if (view === "SIGN_OUT") return <SignOut />
115
+ if (view === "ACCEPT_INVITATION") return <AcceptInvitationCard />
116
+
117
+ const description =
118
+ !credentials && !magicLink && !emailOTP
119
+ ? localization.DISABLED_CREDENTIALS_DESCRIPTION
120
+ : localization[`${view}_DESCRIPTION` as keyof typeof localization]
121
+
122
+ return (
123
+ <Card className={cn("w-full max-w-sm", className, classNames?.base)}>
124
+ <CardHeader className={classNames?.header}>
125
+ {cardHeader ? (
126
+ cardHeader
127
+ ) : (
128
+ <>
129
+ <CardTitle
130
+ className={cn(
131
+ "text-lg md:text-xl",
132
+ classNames?.title
133
+ )}
134
+ >
135
+ {localization[view as keyof typeof localization]}
136
+ </CardTitle>
137
+ {description && (
138
+ <CardDescription
139
+ className={cn(
140
+ "text-xs md:text-sm",
141
+ classNames?.description
142
+ )}
143
+ >
144
+ {description}
145
+ </CardDescription>
146
+ )}
147
+ </>
148
+ )}
149
+ </CardHeader>
150
+
151
+ <CardContent className={cn("grid gap-6", classNames?.content)}>
152
+ {oneTap &&
153
+ ["SIGN_IN", "SIGN_UP", "MAGIC_LINK", "EMAIL_OTP"].includes(
154
+ view as string
155
+ ) && (
156
+ <OneTap
157
+ localization={localization}
158
+ redirectTo={redirectTo}
159
+ />
160
+ )}
161
+
162
+ {(credentials || magicLink || emailOTP) && (
163
+ <div className="grid gap-4">
164
+ <AuthForm
165
+ classNames={classNames?.form}
166
+ callbackURL={callbackURL}
167
+ isSubmitting={isSubmitting}
168
+ localization={localization}
169
+ otpSeparators={otpSeparators}
170
+ view={view}
171
+ redirectTo={redirectTo}
172
+ setIsSubmitting={setIsSubmitting}
173
+ />
174
+
175
+ {magicLink &&
176
+ ((credentials &&
177
+ [
178
+ "FORGOT_PASSWORD",
179
+ "SIGN_UP",
180
+ "SIGN_IN",
181
+ "MAGIC_LINK",
182
+ "EMAIL_OTP"
183
+ ].includes(view as string)) ||
184
+ (emailOTP && view === "EMAIL_OTP")) && (
185
+ <MagicLinkButton
186
+ classNames={classNames}
187
+ localization={localization}
188
+ view={view}
189
+ isSubmitting={isSubmitting}
190
+ />
191
+ )}
192
+
193
+ {emailOTP &&
194
+ ((credentials &&
195
+ [
196
+ "FORGOT_PASSWORD",
197
+ "SIGN_UP",
198
+ "SIGN_IN",
199
+ "MAGIC_LINK",
200
+ "EMAIL_OTP"
201
+ ].includes(view as string)) ||
202
+ (magicLink &&
203
+ ["SIGN_IN", "MAGIC_LINK"].includes(
204
+ view as string
205
+ ))) && (
206
+ <EmailOTPButton
207
+ classNames={classNames}
208
+ localization={localization}
209
+ view={view}
210
+ isSubmitting={isSubmitting}
211
+ />
212
+ )}
213
+ </div>
214
+ )}
215
+
216
+ {view !== "RESET_PASSWORD" &&
217
+ (social?.providers?.length ||
218
+ genericOAuth?.providers?.length ||
219
+ (view === "SIGN_IN" && passkey)) && (
220
+ <>
221
+ {(credentials || magicLink || emailOTP) && (
222
+ <div
223
+ className={cn(
224
+ "flex items-center gap-2",
225
+ classNames?.continueWith
226
+ )}
227
+ >
228
+ <Separator
229
+ className={cn(
230
+ "!w-auto grow",
231
+ classNames?.separator
232
+ )}
233
+ />
234
+ <span className="flex-shrink-0 text-muted-foreground text-sm">
235
+ {localization.OR_CONTINUE_WITH}
236
+ </span>
237
+ <Separator
238
+ className={cn(
239
+ "!w-auto grow",
240
+ classNames?.separator
241
+ )}
242
+ />
243
+ </div>
244
+ )}
245
+
246
+ <div className="grid gap-4">
247
+ {(social?.providers?.length ||
248
+ genericOAuth?.providers?.length) && (
249
+ <div
250
+ className={cn(
251
+ "flex w-full items-center justify-between gap-4",
252
+ socialLayout === "horizontal" &&
253
+ "flex-wrap",
254
+ socialLayout === "vertical" &&
255
+ "flex-col",
256
+ socialLayout === "grid" &&
257
+ "grid grid-cols-2"
258
+ )}
259
+ >
260
+ {social?.providers?.map((provider) => {
261
+ const socialProvider =
262
+ socialProviders.find(
263
+ (socialProvider) =>
264
+ socialProvider.provider ===
265
+ provider
266
+ )
267
+ if (!socialProvider) return null
268
+ return (
269
+ <ProviderButton
270
+ key={provider}
271
+ classNames={classNames}
272
+ callbackURL={callbackURL}
273
+ isSubmitting={isSubmitting}
274
+ localization={localization}
275
+ provider={socialProvider}
276
+ redirectTo={redirectTo}
277
+ setIsSubmitting={
278
+ setIsSubmitting
279
+ }
280
+ socialLayout={socialLayout}
281
+ />
282
+ )
283
+ })}
284
+ {genericOAuth?.providers?.map(
285
+ (provider) => (
286
+ <ProviderButton
287
+ key={provider.provider}
288
+ classNames={classNames}
289
+ callbackURL={callbackURL}
290
+ isSubmitting={isSubmitting}
291
+ localization={localization}
292
+ provider={provider}
293
+ redirectTo={redirectTo}
294
+ setIsSubmitting={
295
+ setIsSubmitting
296
+ }
297
+ socialLayout={socialLayout}
298
+ other
299
+ />
300
+ )
301
+ )}
302
+ </div>
303
+ )}
304
+
305
+ {passkey &&
306
+ [
307
+ "SIGN_IN",
308
+ "MAGIC_LINK",
309
+ "EMAIL_OTP",
310
+ "RECOVER_ACCOUNT",
311
+ "TWO_FACTOR",
312
+ "FORGOT_PASSWORD"
313
+ ].includes(view as string) && (
314
+ <PasskeyButton
315
+ classNames={classNames}
316
+ isSubmitting={isSubmitting}
317
+ localization={localization}
318
+ redirectTo={redirectTo}
319
+ setIsSubmitting={setIsSubmitting}
320
+ />
321
+ )}
322
+ </div>
323
+ </>
324
+ )}
325
+ </CardContent>
326
+
327
+ {credentials && signUp && (
328
+ <CardFooter
329
+ className={cn(
330
+ "justify-center gap-1.5 text-muted-foreground text-sm",
331
+ classNames?.footer
332
+ )}
333
+ >
334
+ {view === "SIGN_IN" ||
335
+ view === "MAGIC_LINK" ||
336
+ view === "EMAIL_OTP" ? (
337
+ localization.DONT_HAVE_AN_ACCOUNT
338
+ ) : view === "SIGN_UP" ? (
339
+ localization.ALREADY_HAVE_AN_ACCOUNT
340
+ ) : (
341
+ <ArrowLeftIcon className="size-3" />
342
+ )}
343
+
344
+ {view === "SIGN_IN" ||
345
+ view === "MAGIC_LINK" ||
346
+ view === "EMAIL_OTP" ||
347
+ view === "SIGN_UP" ? (
348
+ <Link
349
+ className={cn(
350
+ "text-foreground underline",
351
+ classNames?.footerLink
352
+ )}
353
+ href={`${basePath}/${viewPaths[(view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP") ? "SIGN_UP" : "SIGN_IN"]}${
354
+ isHydrated ? window.location.search : ""
355
+ }`}
356
+ >
357
+ <Button
358
+ variant="link"
359
+ size="sm"
360
+ className={cn(
361
+ "px-0 text-foreground underline",
362
+ classNames?.footerLink
363
+ )}
364
+ >
365
+ {view === "SIGN_IN" ||
366
+ view === "MAGIC_LINK" ||
367
+ view === "EMAIL_OTP"
368
+ ? localization.SIGN_UP
369
+ : localization.SIGN_IN}
370
+ </Button>
371
+ </Link>
372
+ ) : (
373
+ <Button
374
+ variant="link"
375
+ size="sm"
376
+ className={cn(
377
+ "px-0 text-foreground underline",
378
+ classNames?.footerLink
379
+ )}
380
+ onClick={() => window.history.back()}
381
+ >
382
+ {localization.GO_BACK}
383
+ </Button>
384
+ )}
385
+ </CardFooter>
386
+ )}
387
+ </Card>
388
+ )
389
+ }
@@ -0,0 +1,53 @@
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 EmailOTPButtonProps {
12
+ classNames?: AuthViewClassNames
13
+ isSubmitting?: boolean
14
+ localization: Partial<AuthLocalization>
15
+ view: AuthViewPath
16
+ }
17
+
18
+ export function EmailOTPButton({
19
+ classNames,
20
+ isSubmitting,
21
+ localization,
22
+ view
23
+ }: EmailOTPButtonProps) {
24
+ const { viewPaths, navigate, basePath } = useContext(AuthUIContext)
25
+
26
+ return (
27
+ <Button
28
+ className={cn(
29
+ "w-full",
30
+ classNames?.form?.button,
31
+ classNames?.form?.secondaryButton
32
+ )}
33
+ disabled={isSubmitting}
34
+ type="button"
35
+ variant="secondary"
36
+ onClick={() =>
37
+ navigate(
38
+ `${basePath}/${view === "EMAIL_OTP" ? viewPaths.SIGN_IN : viewPaths.EMAIL_OTP}${window.location.search}`
39
+ )
40
+ }
41
+ >
42
+ {view === "EMAIL_OTP" ? (
43
+ <LockIcon className={classNames?.form?.icon} />
44
+ ) : (
45
+ <MailIcon className={classNames?.form?.icon} />
46
+ )}
47
+ {localization.SIGN_IN_WITH}{" "}
48
+ {view === "EMAIL_OTP"
49
+ ? localization.PASSWORD
50
+ : localization.EMAIL_OTP}
51
+ </Button>
52
+ )
53
+ }