Email OTP
better-auth-ui/email-otpFreeComponent
Email OTP plugin: passwordless sign-in with an emailed code, plus code-based replacements for email verification, password reset, and email changes.
Live preview
live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://better-auth-ui.com/r/email-otp.jsonSource
1"use client"23import { authMutationKeys } from "@better-auth-ui/core"4import {5 type EmailOtpAuthClient,6 useAuth,7 useAuthPlugin,8 useSendVerificationOtp,9 useSignInEmailOtp10} from "@better-auth-ui/react"11import { useIsMutating } from "@tanstack/react-query"12import { type SyntheticEvent, useState } from "react"1314import { Button } from "@/components/ui/button"15import {16 Card,17 CardContent,18 CardDescription,19 CardHeader,20 CardTitle21} from "@/components/ui/card"22import {23 Field,24 FieldDescription,25 FieldError,26 FieldGroup,27 FieldLabel,28 FieldSeparator29} from "@/components/ui/field"30import { Input } from "@/components/ui/input"31import { Spinner } from "@/components/ui/spinner"32import { emailOtpPlugin } from "@/lib/auth/email-otp-plugin"33import { useResendCooldown } from "@/lib/auth/use-resend-cooldown"34import { useSignInContinuation } from "@/lib/auth/use-sign-in-continuation"35import { cn } from "@/lib/utils"36import { OpenEmailButton } from "../open-email-button"37import { OtpField } from "../otp-field"38import { ProviderButtons, type SocialLayout } from "../provider-buttons"3940export type EmailOtpProps = {41 className?: string42 socialLayout?: SocialLayout43 socialPosition?: "top" | "bottom"44}4546/**47 * Passwordless sign-in with an emailed one-time code.48 *49 * Two steps on one route: enter an email, then enter the code that arrives.50 * The email step never reveals whether an account exists — the server decides51 * whether the code creates an account, mirroring `emailOTP({ disableSignUp })`.52 *53 * @param socialLayout - Provider button layout.54 * @param socialPosition - `"top"` or `"bottom"`. Defaults to `"bottom"`.55 */56export function EmailOtp({57 className,58 socialLayout,59 socialPosition = "bottom"60}: EmailOtpProps) {61 const {62 authClient,63 basePaths,64 emailAndPassword,65 localization,66 plugins,67 socialProviders,68 viewPaths,69 Link70 } = useAuth()71 const { localization: emailOtpLocalization, otpLength } =72 useAuthPlugin(emailOtpPlugin)7374 const otpClient = authClient as EmailOtpAuthClient75 const continueSignIn = useSignInContinuation()76 const { cooldown, isCoolingDown, startCooldown } = useResendCooldown()7778 const [email, setEmail] = useState("")79 const [code, setCode] = useState("")80 const [codeSent, setCodeSent] = useState(false)81 const [fieldErrors, setFieldErrors] = useState<{ email?: string }>({})8283 const { mutate: sendVerificationOtp, isPending: isSending } =84 useSendVerificationOtp(otpClient, {85// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from better-auth-ui
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Account Settingsaccount-settings | better-auth-ui | Components | Free | 2 deps | |
| Active Sessionsactive-sessions | better-auth-ui | Components | Free | 5 deps · 2 files | |
| Additional Fieldadditional-field | better-auth-ui | Components | Free | 5 deps | |
| Adminadmin | better-auth-ui | Components | Free | 4 deps · 3 files | |
| Anonymousanonymous | better-auth-ui | Components | Free | 4 deps · 3 files | |
| API Keyapi-key | better-auth-ui | Components | Free | 4 deps · 10 files | |
| Authauth | better-auth-ui | Components | Free | 2 deps | |
| Auth Providerauth-provider | better-auth-ui | Components | Free | 4 deps · 2 files |
