Username
Add username-based sign-in and real-time availability checking to your authentication flow.
The username plugin adds username-based authentication to your auth UI. Users can sign in with a username instead of an email address, and optionally check username availability during sign-up and profile updates.
It contributes:
- A
<SignInUsername />view that accepts both username and email, routing to the appropriate sign-in method - A
<UsernameField />renderer for the username additional field with real-time availability checking useSignInUsernameanduseIsUsernameAvailablehooks- Automatic username field injection into sign-up and user profile forms
Setup
The username plugin requires no additional UI installation — the components are built-in. You only need to configure the Better Auth server plugin and register the client plugin.
Install the Better Auth plugin
Install the better-auth package and add it to your Better Auth server config:
import { betterAuth } from "better-auth"
import { username } from "better-auth/plugins"
export const auth = betterAuth({
// ...
plugins: [
username()
]
})Install the matching client plugin
Add usernameClient() to your auth client so authClient.signIn.username and authClient.username.* are available:
import { createAuthClient } from "better-auth/react"
import { usernameClient } from "better-auth/client/plugins"
export const authClient = createAuthClient({
plugins: [usernameClient()]
})Register the UI plugin
Pass usernamePlugin() to <AuthProvider>:
import { usernamePlugin } from "@/lib/auth/username-plugin"
import { AuthProvider } from "@/components/auth/auth-provider"
<AuthProvider
authClient={authClient}
navigate={navigate}
plugins={[usernamePlugin()]}
>
{children}
</AuthProvider>Components
<SignIn />
<SignUp />
<UserProfile />
User profile
Options
Prop
Type
Localization
Prop
Type
Last updated on