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/username

Username

better-auth-ui/username
FreeComponent

Username plugin: username-based sign-in form and availability checking field. Registers a sign-in view that accepts both username and email, and a username field with real-time availability checking rendered on the sign-up form.

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/username.json

Source

src/components/auth/username/username-field.tsxbetter-auth-ui.com/r/username.json
1"use client"
2
3import {
4 type UsernameAuthClient,
5 useAuth,
6 useAuthPlugin,
7 useIsUsernameAvailable
8} from "@better-auth-ui/react"
9import { useDebouncer } from "@tanstack/react-pacer"
10import { Check, X } from "lucide-react"
11import { useState } from "react"
12import type { AdditionalFieldProps } from "@/components/auth/additional-field"
13import { Field, FieldError, FieldLabel } from "@/components/ui/field"
14import {
15 InputGroup,
16 InputGroupAddon,
17 InputGroupInput
18} from "@/components/ui/input-group"
19import { Spinner } from "@/components/ui/spinner"
20import { usernamePlugin } from "@/lib/auth/username-plugin"
21
22/**
23 * Renderer for the `username` additional field. Owns availability checking,
24 * length limits, and visual indicators. `isInvalid` reflects only browser
25 * validation (minLength, required, etc.) — availability feedback is shown
26 * via the icon and `aria-label` without affecting the field's invalid state.
27 */
28export function UsernameField({
29 name,
30 field,
31 isPending
32}: AdditionalFieldProps) {
33 const { authClient, localization: authLocalization } = useAuth()
34 const {
35 localization,
36 minUsernameLength,
37 maxUsernameLength,
38 isUsernameAvailable: checkAvailability,
39 usernamePrefix
40 } = useAuthPlugin(usernamePlugin)
41
42 const currentUsername = String(field.defaultValue ?? "")
43 const [value, setValue] = useState(currentUsername)
44 const [error, setError] = useState<string>()
45
46 const {
47 mutate: requestAvailability,
48 data: availability,
49 error: availabilityError,
50 reset: resetAvailability
51 } = useIsUsernameAvailable(authClient as UsernameAuthClient, {
52 onError: () => {}
53 })
54
55 const debouncer = useDebouncer(
56 (next: string) => {
57 const trimmed = next.trim()
58 if (!trimmed || trimmed === currentUsername) {
59 resetAvailability()
60 return
61 }
62
63 requestAvailability({ username: trimmed })
64 },
65 { wait: 500 }
66 )
67
68 function handleChange(next: string) {
69 setValue(next)
70 setError(undefined)
71 resetAvailability()
72
73 if (checkAvailability) {
74 debouncer.maybeExecute(next)
75 }
76 }
77
78 const isCheckingAvailability =
79 !!checkAvailability && !!value.trim() && value.trim() !== currentUsername
80
81 return (
82 <Field data-invalid={!!error}>
83 <FieldLabel htmlFor={name}>{field.label}</FieldLabel>
84
85 <InputGroup>
86 {usernamePrefix && (
87 <InputGroupAddon align="inline-start">
88 {usernamePrefix}
89 </InputGroupAddon>
90 )}
91
92// … truncated

What it pulls in

npm packages

  • @better-auth-ui/react@latest
  • @better-auth-ui/core@latest
  • @tanstack/react-pacer
  • better-auth
  • lucide-react

Other registry items

  • badge
  • button
  • card
  • checkbox
  • field
  • input
  • input-group
  • separator
  • sonner
  • spinner
  • https://better-auth-ui.com/r/radix-nova/additional-field.json

Files it writes

  • src/lib/auth/auth-plugin.ts
  • src/lib/auth/username-plugin.ts
  • src/components/auth/username/username-field.tsx
  • src/components/auth/username/sign-in-username.tsx
  • src/components/auth/last-login-method/last-used-badge.tsx
  • src/lib/auth/use-sign-in-continuation.ts
  • src/lib/auth/two-factor-methods.ts

Facts

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

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