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.
These examples assume you've already defined AppAuthSchema. If you want a complete setup from entity definitions through Axum mounting, start with the Axum integration guide .
use better_auth :: plugins :: EmailPasswordPlugin ;
let auth = BetterAuth :: < AppAuthSchema > :: new (config)
. store (store)
. plugin (
EmailPasswordPlugin :: new ()
. enable_signup ( true )
. password_min_length ( 8 )
. require_email_verification ( false )
)
. build ()
.await? ;
Option Type Default Description enable_signupbooltrueAllow new user registration require_email_verificationboolfalseRequire verified email before sign-in password_min_lengthusize8Minimum password length
POST /sign-up/email
Content-Type : application/json
{
"name" : "Alice" ,
"email" : "[email protected] " ,
"password" : "secure_password" ,
"username" : "alice" ,
"displayUsername" : "Alice"
}
Field Required Description nameYes Display name emailYes Valid email address passwordYes Must meet minimum length usernameNo Unique username for username-based sign-in displayUsernameNo Case-preserved display version of username callbackURLNo Redirect URL after sign-up
{
"token" : "session_abc123..." ,
"user" : {
"id" : "uuid" ,
"name" : "Alice" ,
"email" : "[email protected] " ,
"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
Field Required Description emailYes Registered email address passwordYes Account password callbackURLNo Redirect URL after sign-in rememberMeNo 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