Skip to main content
The username plugin extends email/password authentication so users can sign in with a username instead of (or in addition to) their email address.

Installation

1

Add the server plugin

Enable emailAndPassword and add the username plugin:
auth.ts
2

Run the database migration

The plugin adds username and displayUsername columns to the user table:
3

Add the client plugin

auth-client.ts

Usage

Sign up with a username

Pass a username field to the existing signUp.email method:
sign-up.ts
If only username is provided, displayUsername is automatically set to the pre-normalized value of username. Usernames are lowercased by default — "JaneDoe" and "janedoe" are treated as the same username.

Sign in with a username

Use the signIn.username method added by the plugin:
sign-in.ts

Update a username

update-username.ts

Check username availability

check-username.ts

Configuration options

All options are passed to username() on the server:
auth.ts

Database schema

The plugin adds two optional columns to the user table: