Skip to content

Username

Username sign-in is part of EmailPasswordPlugin.

Terminal window
better-auth-rs generate --plugins username -o src/auth_schema.rs

Apply the schema changes, then enable username support:

use crate::auth_schema::AppAuthSchema;
use better_auth::plugins::EmailPasswordPlugin;
use better_auth::sqlx::SqlxStore;
use better_auth::{AuthConfig, AuthResult, BetterAuth};
async fn build_auth(
config: AuthConfig,
store: SqlxStore<AppAuthSchema>,
) -> AuthResult<BetterAuth<AppAuthSchema>> {
BetterAuth::<AppAuthSchema>::new(config)
.store(store)
.plugin(EmailPasswordPlugin::new().enable_username(true))
.build()
.await
}

Sign-in uses /sign-in/username; email signup also accepts a username. The default policy lowercases ASCII usernames and allows 3–30 characters.

Use username_config to change length bounds, normalization, validators, or input policies. Validation order depends on the selected pre/post-normalization policy; see the username implementation for the complete options.

See the official username guide.