BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/better-auth-ui/two-factor

Two-Factor

better-auth-ui/two-factor
FreeComponent

Two-factor plugin: the post-password challenge for authenticator, emailed, and backup codes, plus the settings card for enrollment and backup-code management.

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/two-factor.json

Source

src/components/auth/otp-field.tsxbetter-auth-ui.com/r/two-factor.json
1"use client"
2
3import { REGEXP_ONLY_DIGITS } from "input-otp"
4import { useId } from "react"
5
6import { Field, FieldError, FieldLabel } from "@/components/ui/field"
7import {
8 InputOTP,
9 InputOTPGroup,
10 InputOTPSlot
11} from "@/components/ui/input-otp"
12import { cn } from "@/lib/utils"
13
14export type OtpFieldProps = {
15 /** Visible label rendered above the slots. */
16 label: string
17 /** Number of slots — keep in sync with the server's code length. */
18 length: number
19 value: string
20 onChange: (value: string) => void
21 onComplete?: (value: string) => void
22 autoFocus?: boolean
23 className?: string
24 errorMessage?: string
25 disabled?: boolean
26 name?: string
27}
28
29/** Strip everything the numeric slots can't hold — pasted codes often carry spaces or dashes. */
30function normalizeCode(value: string) {
31 return value.replace(/\D/g, "")
32}
33
34/**
35 * Labelled one-time-code input.
36 *
37 * Shared by every code-based flow (email OTP, two-factor challenge,
38 * two-factor enrollment) so slot sizing, pasting, and error wiring behave the
39 * same everywhere.
40 *
41 * @param label - Visible label, also used as the accessible name.
42 * @param length - Number of code characters.
43 * @param errorMessage - Rendered below the slots when set.
44 */
45export function OtpField({
46 autoFocus,
47 className,
48 disabled,
49 errorMessage,
50 label,
51 length,
52 name,
53 onChange,
54 onComplete,
55 value
56}: OtpFieldProps) {
57 const inputId = useId()
58
59 return (
60 <Field className={cn(className)} data-invalid={!!errorMessage}>
61 <FieldLabel htmlFor={inputId}>{label}</FieldLabel>
62
63 <InputOTP
64 aria-invalid={!!errorMessage}
65 aria-label={label}
66 autoComplete="one-time-code"
67 autoFocus={autoFocus}
68 containerClassName="w-full justify-center"
69 disabled={disabled}
70 id={inputId}
71 inputMode="numeric"
72 maxLength={length}
73 name={name}
74 pasteTransformer={normalizeCode}
75 pattern={REGEXP_ONLY_DIGITS}
76 value={value}
77 onChange={(next) => onChange(normalizeCode(next))}
78 onComplete={(completedCode) =>
79 onComplete?.(normalizeCode(completedCode))
80 }
81 >
82 <InputOTPGroup>
83 {Array.from({ length }, (_, slotIndex) => (
84 <InputOTPSlot
85 index={slotIndex}
86 key={`otp-slot-${String(slotIndex + 1)}`}
87 />
88 ))}
89 </InputOTPGroup>
90 </InputOTP>
91
92 <FieldError>{errorMessage}</FieldError>
93 </Field>
94 )
95}

What it pulls in

npm packages

  • @better-auth-ui/react@latest
  • @better-auth-ui/core@latest
  • better-auth
  • input-otp
  • lucide-react

Other registry items

  • alert-dialog
  • button
  • card
  • checkbox
  • dialog
  • field
  • input
  • input-group
  • input-otp
  • skeleton
  • sonner
  • spinner
  • https://better-auth-ui.com/r/radix-nova/sign-in.json
  • https://better-auth-ui.com/r/radix-nova/username.json

Files it writes

  • src/lib/auth/auth-plugin.ts
  • src/lib/auth/two-factor-plugin.ts
  • src/lib/auth/use-resend-cooldown.ts
  • src/lib/auth/use-sign-in-continuation.ts
  • src/lib/auth/two-factor-methods.ts
  • src/lib/auth/use-two-factor-password.ts
  • src/components/auth/otp-field.tsx
  • src/components/auth/two-factor/two-factor-challenge.tsx
  • src/components/auth/two-factor/two-factor-settings.tsx
  • src/components/auth/two-factor/enable-two-factor-dialog.tsx
  • src/components/auth/two-factor/disable-two-factor-dialog.tsx
  • src/components/auth/two-factor/regenerate-backup-codes-dialog.tsx
  • src/components/auth/two-factor/backup-codes.tsx
  • src/components/auth/use-is-hydrated.ts

Facts

Registry
better-auth-ui
Type
registry:component
Access
Free
Files written
14
Licence
MIT
First indexed
2026-08-02
Last confirmed
today

Go to the source

Docs on better-auth-ui better-auth-ui.com better-auth-ui/better-auth-ui on GitHub Raw registry item This item as JSON

More from better-auth-ui

All 49 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Account Settingsaccount-settingsbetter-auth-uiComponentsFree2 deps
Active Sessionsactive-sessionsbetter-auth-uiComponentsFree5 deps · 2 files
Additional Fieldadditional-fieldbetter-auth-uiComponentsFree5 deps
Adminadminbetter-auth-uiComponentsFree4 deps · 3 files
Anonymousanonymousbetter-auth-uiComponentsFree4 deps · 3 files
API Keyapi-keybetter-auth-uiComponentsFree4 deps · 10 files
Authauthbetter-auth-uiComponentsFree2 deps
Auth Providerauth-providerbetter-auth-uiComponentsFree4 deps · 2 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex