BETTER-AUTH. UI
Plugins

Username

Add username-based sign-in and real-time availability checking to your Solid/Zaidan 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
  • Solid username availability and username sign-in mutations through the Better Auth client
  • Automatic username field injection into sign-up and user profile forms

Setup

The username plugin requires the Better Auth server plugin, the matching client plugin, and the copied Zaidan UI plugin wrapper.

Install the Better Auth plugin

Install the better-auth server plugin and add it to your Better Auth config:

src/lib/auth.ts
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:

src/lib/auth-client.ts
import { createAuthClient } from "@better-auth-ui/solid"
import { usernameClient } from "better-auth/client/plugins"

export const authClient = createAuthClient({
  plugins: [usernameClient()] 
})

Register the UI plugin

Run the shadcn CLI to install the Username UI plugin wrapper and copied Solid components:

npx shadcn@latest add https://better-auth-ui.com/r/solid/username.json

Then pass usernamePlugin() to <AuthProvider>:

src/components/providers.tsx
import { AuthProvider } from "@/components/auth/auth-provider"
import { usernamePlugin } from "@/lib/auth/username-plugin"
import { authClient } from "@/lib/auth-client"

export function Providers(props: { children?: JSX.Element }) {
  return (
    <AuthProvider
      authClient={authClient}
      plugins={[
        usernamePlugin() 
      ]}
    >
      {props.children}
    </AuthProvider>
  )
}

Components

These previews use mocked auth clients and do not call live Better Auth endpoints.

<SignIn />

<SignUp />

<UserProfile />

Options

Prop

Type

Localization

Prop

Type

Last updated on

On this page