Better Auth RS
The most comprehensive authentication framework for Rust. Inspired by Better Auth.
Features
- Plugin Architecture - Extend and customize authentication flows
- Type Safety - Leverages Rust's type system for compile-time guarantees
- Async First - Built on Tokio with full async/await support
- Database Agnostic - Support for multiple databases through adapter pattern
- Web Framework Integration - First-class Axum support
- OpenAPI - Built-in OpenAPI spec generation
- Middleware - CSRF, CORS, rate limiting, body size limits
Quick Start
Add to your Cargo.toml:
[]
= "0.4"
use ;
use EmailPasswordPlugin;
use MemoryDatabaseAdapter;
async
Axum Integration
Enable the axum feature:
[]
= { = "0.4", = ["axum"] }
use ;
use EmailPasswordPlugin;
use MemoryDatabaseAdapter;
use AxumIntegration;
use Arc;
async
Crate Structure
| Crate | Description |
|---|---|
better-auth |
Main crate, re-exports and Axum integration |
better-auth-core |
Core abstractions: traits, config, middleware, error handling |
better-auth-api |
Plugin implementations (email/password, session management, organization, etc.) |
better-auth-derive |
Derive macros for custom entity types (AuthUser, MemoryUser, etc.) |
Plugins
| Plugin | Status | Description |
|---|---|---|
| Email/Password | Done | Sign up/sign in with email & password, username support |
| Password Management | Done | Password reset, change, set |
| Email Verification | Done | Email verification workflows |
| Session Management | Done | Session listing and revocation |
| Account Management | Done | Account linking and unlinking |
| Organization | Done | Multi-tenant organizations with RBAC |
| OAuth | Planned | Social sign-in (OAuth 2.0) |
| Two-Factor Auth | Planned | TOTP, backup codes |
API Endpoints
Endpoints are registered by plugins:
# Authentication
POST /sign-up/email # User registration
POST /sign-in/email # Email-based login
POST /sign-in/username # Username-based login
# Password Management
POST /forget-password # Password reset request
POST /reset-password # Password reset confirmation
POST /change-password # Change password (authenticated)
POST /set-password # Set password (authenticated)
# Email Verification
POST /send-verification-email
POST /verify-email
# Session Management
GET /sessions # List active sessions
POST /revoke-session # Revoke a session
# Account Management
GET /accounts # List linked accounts
POST /unlink-account # Unlink an account
# Organization (multi-tenant)
POST /organization/create # Create organization
POST /organization/update # Update organization
POST /organization/delete # Delete organization
GET /organization/list # List user's organizations
GET /organization/get-full-organization
POST /organization/set-active # Set active organization
POST /organization/leave # Leave organization
POST /organization/check-slug # Check slug availability
# Organization Members
GET /organization/get-active-member
GET /organization/list-members
POST /organization/remove-member
POST /organization/update-member-role
# Organization Invitations
POST /organization/invite-member
GET /organization/get-invitation
GET /organization/list-invitations
POST /organization/accept-invitation
POST /organization/reject-invitation
POST /organization/cancel-invitation
# RBAC
POST /organization/has-permission # Check permissions
Database Adapters
- MemoryDatabaseAdapter - In-memory storage for development and testing
- SqlxAdapter - PostgreSQL with connection pooling (
sqlx-postgresfeature)
Migrations
SQL migration files are provided in the migrations/ directory. Apply them with any migration tool or directly:
Feature Flags
[]
= [] # Axum web framework integration
= [] # Custom entity derive macros (AuthUser, MemoryUser, etc.)
= [] # PostgreSQL database support
= [] # Redis caching (planned)
Examples
See examples/README.md for detailed documentation.
# Basic usage (in-memory)
# PostgreSQL
# Axum web server with interactive demo
# Custom entity types with derive macros
# SQLx custom entities (standalone project)
# Sea-ORM with migration (standalone project)
License
Licensed under either of:
at your option.