Email & Password
Sign up and sign in with email, password, and optional username.
The EmailPasswordPlugin handles user registration and authentication via email/password or username/password.
use better_auth::plugins::EmailPasswordPlugin;
let auth = BetterAuth::new(config)
.database(database)
.plugin(
EmailPasswordPlugin::new()
.enable_signup(true)
.password_min_length(8)
.require_email_verification(false)
)
.build()
.await?;
| Option | Type | Default | Description |
|---|
enable_signup | bool | true | Allow new user registration |
require_email_verification | bool | false | Require verified email before sign-in |
password_min_length | usize | 8 | Minimum password length |
POST /sign-up/email
Content-Type: application/json
{
"name": "Alice",
"email": "alice@example.com",
"password": "secure_password",
"username": "alice",
"displayUsername": "Alice"
}
| Field | Required | Description |
|---|
name | Yes | Display name |
email | Yes | Valid email address |
password | Yes | Must meet minimum length |
username | No | Unique username for username-based sign-in |
displayUsername | No | Case-preserved display version of username |
callbackURL | No | Redirect URL after sign-up |
{
"token": "session_abc123...",
"user": {
"id": "uuid",
"name": "Alice",
"email": "alice@example.com",
"emailVerified": false,
"username": "alice",
"displayUsername": "Alice",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
}
| Status | Condition |
|---|
| 400 | Invalid email format or password too short |
| 409 | Email or username already exists |
POST /sign-in/email
Content-Type: application/json
{
"email": "alice@example.com",
"password": "secure_password"
}
| Field | Required | Description |
|---|
email | Yes | Registered email address |
password | Yes | Account password |
callbackURL | No | Redirect URL after sign-in |
rememberMe | No | Extended session duration |
{
"redirect": false,
"token": "session_abc123...",
"url": null,
"user": { ... }
}
| Status | Condition |
|---|
| 400 | Missing or invalid email format |
| 401 | Invalid credentials |
POST /sign-in/username
Content-Type: application/json
{
"username": "alice",
"password": "secure_password"
}
Same format as email sign-in.
| Status | Condition |
|---|
| 400 | Missing username or password |
| 401 | Invalid credentials |