| Crates.io | better-auth |
| lib.rs | better-auth |
| version | 0.0.1-alpha.2 |
| created_at | 2025-07-25 02:44:41.602752+00 |
| updated_at | 2025-08-14 06:50:48.223532+00 |
| description | The most comprehensive authentication framework for Rust |
| homepage | |
| repository | https://github.com/better-auth-rs/better-auth-rs |
| max_upload_size | |
| id | 1767134 |
| size | 650,752 |
A Rust authentication framework inspired by Better-Auth, providing a plugin-based architecture and type-safe authentication solutions.
use better_auth::{BetterAuth, AuthConfig};
use better_auth::plugins::EmailPasswordPlugin;
use better_auth::adapters::MemoryDatabaseAdapter;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create configuration
let config = AuthConfig::new("your-very-secure-secret-key-at-least-32-chars-long")
.base_url("http://localhost:3000")
.password_min_length(8);
// Create authentication system
let auth = BetterAuth::new(config)
.database(MemoryDatabaseAdapter::new())
.plugin(EmailPasswordPlugin::new().enable_signup(true))
.build()
.await?;
println!("๐ Authentication system ready!");
println!("Registered plugins: {:?}", auth.plugin_names());
Ok(())
}
use better_auth::{BetterAuth, AuthConfig};
use better_auth::plugins::EmailPasswordPlugin;
use better_auth::adapters::MemoryDatabaseAdapter;
use better_auth::handlers::AxumIntegration;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AuthConfig::new("your-secret-key");
let auth = Arc::new(
BetterAuth::new(config)
.database(MemoryDatabaseAdapter::new())
.plugin(EmailPasswordPlugin::new())
.build()
.await?
);
// Create Axum router
let app = auth.axum_router();
// Start server
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}
better-auth/
โโโ src/
โ โโโ core/ # Core functionality
โ โ โโโ auth.rs # Main authentication logic
โ โ โโโ config.rs # Configuration management
โ โ โโโ plugin.rs # Plugin abstraction
โ โ โโโ session.rs # Session management
โ โโโ plugins/ # Authentication plugins
โ โ โโโ email_password.rs
โ โ โโโ oauth.rs
โ โ โโโ two_factor.rs
โ โโโ adapters/ # Database and cache adapters
โ โ โโโ database.rs
โ โ โโโ cache.rs
โ โโโ handlers/ # Web framework integration
โ โ โโโ axum.rs
โ โโโ error.rs # Error types
โ โโโ types.rs # Core type definitions
โโโ examples/
โโโ basic_usage.rs # Basic authentication example
โโโ postgres_usage.rs # PostgreSQL database example
โโโ axum_server.rs # Complete web server with demo UI
POST /sign-up - User registrationPOST /sign-in - User loginGET /health - Health check[features]
default = []
axum = ["dep:axum", "dep:tower", "dep:tower-http"]
sqlx-postgres = ["dep:sqlx"]
redis-cache = ["dep:redis"]
# Run basic example (in-memory database)
cargo run --example basic_usage
# Run PostgreSQL example
export DATABASE_URL="postgresql://better_auth:password@localhost:5432/better_auth"
cargo run --example postgres_usage --features sqlx-postgres
# Run Axum web server with interactive demo
cargo run --example axum_server --features axum
Then visit:
# Test basic compilation
cargo check
# Test PostgreSQL features
cargo check --features sqlx-postgres
# Test Axum features
cargo check --features axum
Contributions are welcome! Please check the project structure and existing implementations to understand how to add new features.
MIT License
Better Auth Rust - Build secure, scalable authentication systems ๐