Installation
Run the database migration
The plugin adds
username and displayUsername columns to the user table:- migrate
- generate
Usage
Sign up with a username
Pass ausername 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 thesignIn.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 tousername() on the server:
auth.ts
| Option | Type | Default | Description |
|---|---|---|---|
minUsernameLength | number | 3 | Minimum username length. |
maxUsernameLength | number | 30 | Maximum username length. |
usernameValidator | function | — | Custom validation function. Return false to reject. |
displayUsernameValidator | function | — | Custom validation for the display username. |
usernameNormalization | function | false | lowercase | Normalization applied before storing. Pass false to disable. |
displayUsernameNormalization | function | false | none | Normalization applied to displayUsername. |
validationOrder | object | pre-normalization | Set to "post-normalization" to validate after normalizing. |
Database schema
The plugin adds two optional columns to theuser table:
| Column | Type | Description |
|---|---|---|
username | string (unique) | Normalized username. |
displayUsername | string | Un-normalized display version of the username. |