Production authentication storage
Persist users and sessions in a stateful authentication deployment.
Better Auth · Pipe
Configure Better Auth with a supported database connection or adapter so it can persist users, sessions, and other authentication data. Omitting the database enables stateless operation, but most plugins require database storage.
Pass a supported database connection, such as a SQLite instance, to the database option when creating Better Auth. Better Auth uses that connection for persisted users, sessions, and related records; ORM adapters can be used when the connection is managed through an ORM.
betterAuth({ database: connectionOrAdapter })| Name | Type | Description |
|---|---|---|
database | database instance or adapter | Supported database connection or adapter used for Better Auth persistence. |
A configured Better Auth instance that uses the supplied database for authentication data.
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";
export const auth = betterAuth({
database: new Database("./sqlite.db"),
});Creates a Better Auth instance backed by a SQLite database.
Persist users and sessions in a stateful authentication deployment.
Use an existing ORM-managed connection while retaining Better Auth persistence.
Run a minimal setup without configuring persistent storage.
Better Auth uses the configured database to persist users, sessions, and other authentication data. The connection is supplied through the database option in betterAuth.
Follow-up: What can be used instead of a raw database connection? A supported ORM adapter, such as the Drizzle adapter, can be passed through the same database option.
A direct supported database instance can be passed to database, as shown with a SQLite connection. Better Auth also supports configuring PostgreSQL, MySQL, SQLite, and other database setups.
Follow-up: What happens if database is omitted? Better Auth can operate statelessly, although most plugins require a database.
The database stores persistent authentication records, including users and sessions. This enables normal stateful authentication behavior across requests.
Follow-up: Why might a stateless configuration still be unsuitable? Plugins commonly depend on database-backed persistence, so omitting the database can prevent their use.
database adaptersDrizzle adapterstateless session managementPostgreSQLMySQLSQLite