Username
The username plugin wraps the email and password authenticator and adds username support. This allows users to sign in and sign up with their username instead of their email.
Installation
Add Plugin to the server
Migrate the database
Run the migration or generate the schema to add the necessary fields and tables to the database.
See the Schema section to add the fields manually.
Add the client plugin
Usage
Signup with username
To sign up a user with username, you can use the existing signUp.email
function provided by the client. The signUp
function should take a new username
property in the object.
Signin with username
To signin a user with username, you can use the signIn.username
function provided by the client. The signIn
function takes an object with the following properties:
username
: The username of the user.password
: The password of the user.
Update username
To update the username of a user, you can use the updateUser
function provided by the client.
Schema
The plugin requires 1 field to be added to the user table:
Field Name | Type | Key | Description |
---|---|---|---|
username | string | - | The username of the user |
Options
Min Username Length
The minimum length of the username. Default is 3
.
Max Username Length
The maximum length of the username. Default is 30
.
Username Validator
A function that validates the username. The function should return false if the username is invalid. By default, the username should only contain alphanumeric characters and underscores.