Database
SeaORM-backed database integration for Better Auth.
Better Auth uses a SeaORM DatabaseConnection for auth persistence.
The supported public path is:
- Create a
DatabaseConnection. - Run the built-in auth migrations.
- Pass the connection to
BetterAuth::new(config).database(...).
Setup
use better_auth::{run_migrations, AuthConfig, BetterAuth};
use better_auth::store::{Database, DatabaseConnection};
use better_auth::plugins::EmailPasswordPlugin;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let database = Database::connect("sqlite::memory:").await?;
run_migrations(&database).await?;
let auth_database: DatabaseConnection = database.clone();
let auth = BetterAuth::new(
AuthConfig::new("your-very-secure-secret-key-at-least-32-chars-long")
.base_url("http://localhost:3000"),
)
.database(auth_database)
.plugin(EmailPasswordPlugin::new().enable_signup(true))
.build()
.await?;
// Keep using `database` for your app's own tables and queries.
println!("plugins: {:?}", auth.plugin_names());
Ok(())
}PostgreSQL
For production, pass a PostgreSQL connection string to SeaORM and then run the same migrations:
use better_auth::{run_migrations};
use better_auth::store::Database;
let database = Database::connect("postgresql://user:pass@localhost:5432/mydb").await?;
run_migrations(&database).await?;Testing
Repo-local tests use SQLite through the same DatabaseConnection API plus run_migrations.
The dual-server and client SDK compatibility checks still validate behavior against the TypeScript
reference server.
Notes
run_migrationsrecords Better Auth schema state in thebetter_auth_migrationstable so it can coexist cleanly with your app's own SeaORM migrator history.MemoryCacheAdapteris still available for cache/rate-limit use cases. It is separate from database persistence.