Skip to main content

Crate better_auth

Crate better_auth 

Source
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§

adapters
core
handlers
plugins
types

Structs§

Account
Account linking (for OAuth providers) - matches OpenAPI schema
Argon2Config
Argon2 hashing configuration
AuthConfig
Main configuration for BetterAuth
AuthContext
Context passed to plugin methods
AuthRequest
Authentication request wrapper
AuthResponse
Authentication response wrapper
AuthRoute
Route definition for plugins
BodyLimitConfig
Configuration for body size limit middleware.
BodyLimitMiddleware
Body size limit middleware.
ConsoleEmailProvider
Development email provider that logs emails to stderr.
CorsConfig
Configuration for CORS middleware.
CorsMiddleware
CORS middleware.
CreateAccount
Account creation data
CreateSession
Session creation data
CreateUser
User creation data
CreateVerification
Verification token creation data
CsrfConfig
Configuration for CSRF protection middleware.
CsrfMiddleware
CSRF protection middleware.
DeleteUserResponse
EndpointRateLimit
Rate limit parameters for a single endpoint.
HookedDatabaseAdapter
A database adapter wrapper that calls hooks around the inner adapter’s operations.
JwtConfig
JWT configuration
MemberUserView
Minimal user info for member-related API responses.
MemoryCacheAdapter
In-memory cache adapter for testing and development
MemoryDatabaseAdapter
In-memory database adapter for testing and development
OpenApiBuilder
Builder for constructing an OpenAPI spec from plugins and core routes.
OpenApiSpec
Minimal OpenAPI 3.1.0 spec builder that collects routes from plugins.
Passkey
Passkey authentication - matches OpenAPI schema
PasswordConfig
Password hashing configuration
RateLimitConfig
Configuration for the rate limiting middleware.
RateLimitMiddleware
In-memory sliding-window rate limiter.
Session
Session information - matches OpenAPI schema
SessionConfig
Session-specific configuration
SessionManager
Session manager handles session creation, validation, and cleanup
TwoFactor
Two-factor authentication - matches OpenAPI schema
UpdateUser
User update data
UpdateUserRequest
UpdateUserResponse
User
Core user type - matches OpenAPI schema
Verification
Verification token - matches OpenAPI schema

Enums§

AuthError
Authentication framework error types.
DatabaseError
HttpMethod
HTTP method enumeration
SameSite

Traits§

AuthAccount
Trait representing an account entity (OAuth provider linking).
AuthInvitation
Trait representing an invitation entity.
AuthMember
Trait representing an organization member entity.
AuthOrganization
Trait representing an organization entity.
AuthPasskey
Trait representing a passkey entity.
AuthPlugin
Plugin trait that all authentication plugins must implement.
AuthSession
Trait representing a session entity.
AuthTwoFactor
Trait representing a two-factor authentication entity.
AuthUser
Trait representing a user entity.
AuthVerification
Trait representing a verification token entity.
CacheAdapter
Cache adapter trait for session caching
DatabaseAdapter
Database adapter trait for persistence.
DatabaseHooks
Database lifecycle hooks for intercepting operations.
EmailProvider
Trait for sending emails. Implement this to integrate with your email service (SMTP, SendGrid, SES, etc.).
Middleware
Middleware trait for request/response processing.

Type Aliases§

AuthResult