Expand description
§Better Auth - Rust
A comprehensive authentication framework for Rust, inspired by Better-Auth.
§Quick Start
use better_auth::{AuthBuilder, AuthConfig};
use better_auth::adapters::MemoryDatabaseAdapter;
use better_auth::plugins::EmailPasswordPlugin;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AuthConfig::new("your-secret-key-that-is-at-least-32-chars");
let auth = AuthBuilder::new(config)
.database(MemoryDatabaseAdapter::new())
.plugin(EmailPasswordPlugin::new())
.build()
.await?;
Ok(())
}Re-exports§
pub use core::AuthBuilder;pub use core::BetterAuth;pub use core::TypedAuthBuilder;pub use better_auth_core as types_mod;
Modules§
Structs§
- Account
- Account linking (for OAuth providers) - matches OpenAPI schema
- Argon2
Config - Argon2 hashing configuration
- Auth
Config - Main configuration for BetterAuth
- Auth
Context - Context passed to plugin methods
- Auth
Request - Authentication request wrapper
- Auth
Response - Authentication response wrapper
- Auth
Route - Route definition for plugins
- Body
Limit Config - Configuration for body size limit middleware.
- Body
Limit Middleware - Body size limit middleware.
- Console
Email Provider - Development email provider that logs emails to stderr.
- Cors
Config - Configuration for CORS middleware.
- Cors
Middleware - CORS middleware.
- Create
Account - Account creation data
- Create
Invitation - Invitation creation data
- Create
Member - Member creation data
- Create
Organization - Organization creation data
- Create
Session - Session creation data
- Create
User - User creation data
- Create
Verification - Verification token creation data
- Csrf
Config - Configuration for CSRF protection middleware.
- Csrf
Middleware - CSRF protection middleware.
- Delete
User Response - Endpoint
Rate Limit - Rate limit parameters for a single endpoint.
- Hooked
Database Adapter - A database adapter wrapper that calls hooks around the inner adapter’s operations.
- Invitation
- Organization invitation
- JwtConfig
- JWT configuration
- Member
User View - Minimal user info for member-related API responses.
- Memory
Cache Adapter - In-memory cache adapter for testing and development
- Memory
Database Adapter - In-memory database adapter for testing and development.
- Open
ApiBuilder - Builder for constructing an OpenAPI spec from plugins and core routes.
- Open
ApiSpec - Minimal OpenAPI 3.1.0 spec builder that collects routes from plugins.
- Passkey
- Passkey authentication - matches OpenAPI schema
- Password
Config - Password hashing configuration
- Rate
Limit Config - Configuration for the rate limiting middleware.
- Rate
Limit Middleware - In-memory sliding-window rate limiter.
- Session
- Session information - matches OpenAPI schema
- Session
Config - Session-specific configuration
- Session
Manager - Session manager handles session creation, validation, and cleanup
- TwoFactor
- Two-factor authentication - matches OpenAPI schema
- Update
Organization - Organization update data
- Update
User - User update data
- Update
User Request - Update
User Response - User
- Core user type - matches OpenAPI schema
- Verification
- Verification token - matches OpenAPI schema
Enums§
- Auth
Error - Authentication framework error types.
- Database
Error - Http
Method - HTTP method enumeration
- Invitation
Status - Invitation status
- Same
Site
Traits§
- Account
Ops - Account (OAuth provider linking) persistence operations.
- Auth
Account - Trait representing an account entity (OAuth provider linking).
- Auth
Invitation - Trait representing an invitation entity.
- Auth
Member - Trait representing an organization member entity.
- Auth
Organization - Trait representing an organization entity.
- Auth
Passkey - Trait representing a passkey entity.
- Auth
Plugin - Plugin trait that all authentication plugins must implement.
- Auth
Session - Trait representing a session entity.
- Auth
TwoFactor - Trait representing a two-factor authentication entity.
- Auth
User - Trait representing a user entity.
- Auth
Verification - Trait representing a verification token entity.
- Cache
Adapter - Cache adapter trait for session caching
- Database
Adapter - Database adapter trait for persistence.
- Database
Hooks - Database lifecycle hooks for intercepting operations.
- Email
Provider - Trait for sending emails. Implement this to integrate with your email service (SMTP, SendGrid, SES, etc.).
- Invitation
Ops - Invitation persistence operations.
- Member
Ops - Organization member persistence operations.
- Memory
Account - Construction for account entities stored in memory.
- Memory
Invitation - Construction and mutation for invitation entities stored in memory.
- Memory
Member - Construction and mutation for member entities stored in memory.
- Memory
Organization - Construction and mutation for organization entities stored in memory.
- Memory
Session - Construction and mutation for session entities stored in memory.
- Memory
User - Construction and mutation for user entities stored in memory.
- Memory
Verification - Construction for verification entities stored in memory.
- Middleware
- Middleware trait for request/response processing.
- Organization
Ops - Organization persistence operations.
- Session
Ops - Session persistence operations.
- UserOps
- User persistence operations.
- Verification
Ops - Verification token persistence operations.