Skip to main content

Crate better_auth_diesel_sqlite

Crate better_auth_diesel_sqlite 

Source
Expand description

§better-auth-diesel-sqlite

A SQLite database adapter for better-auth-rs using Diesel ORM with tokio::task::spawn_blocking for non-blocking database access.

This crate implements the full DatabaseAdapter trait and all 10 operation sub-traits, enabling better-auth-rs’s complete plugin ecosystem (API keys, organizations, admin, 2FA, passkeys, OAuth, sessions, and more) to work with SQLite databases.

§Quick Start

use better_auth::{AuthBuilder, AuthConfig};
use better_auth::plugins::{EmailPasswordPlugin, SessionManagementPlugin, ApiKeyPlugin};
use better_auth::plugins::api_key::ApiKeyConfig;
use better_auth_diesel_sqlite::DieselSqliteAdapter;

let adapter = DieselSqliteAdapter::new("sqlite://auth.db").await?;

let config = AuthConfig::new("your-secret-key-at-least-32-chars-long")
    .base_url("http://localhost:8080");

let auth = AuthBuilder::new(config)
    .database(adapter)
    .plugin(EmailPasswordPlugin::new().enable_signup(true))
    .plugin(SessionManagementPlugin::new())
    .plugin(ApiKeyPlugin::with_config(ApiKeyConfig {
        prefix: Some("sk_".to_string()),
        ..ApiKeyConfig::default()
    }))
    .build()
    .await?;

Re-exports§

pub use adapter::DieselSqliteAdapter;
pub use config::PoolConfig;
pub use error::AdapterError;

Modules§

adapter
Core adapter struct and constructors.
config
Adapter configuration types.
error
Error types and conversion to better-auth-core’s AuthError.
models
Diesel model structs for each auth table.
ops
Trait implementations for each *Ops sub-trait of DatabaseAdapter.
schema
Diesel table definitions for better-auth schema.