Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Pipe

database

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.

How it works

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.

Syntax

betterAuth({ database: connectionOrAdapter })

Parameters

NameTypeDescription
databasedatabase instance or adapterSupported database connection or adapter used for Better Auth persistence.

Returns

A configured Better Auth instance that uses the supplied database for authentication data.

Key points

  • The database is the persistence layer for Better Auth data.
  • Stored records include users and sessions, along with other authentication entities.
  • Configure storage by supplying a supported database instance in the database option.
  • ORM users can select one of Better Auth's built-in adapters instead of passing a raw connection.

Common mistakes

  • Stateless mode is possible without a database, but many plugins still need persistent database storage.
  • Omitting the database switches the setup to stateless operation rather than normal persisted storage.

Example: Configure SQLite storage

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.

When to use it

Production authentication storage

Persist users and sessions in a stateful authentication deployment.

ORM integration

Use an existing ORM-managed connection while retaining Better Auth persistence.

Stateless authentication

Run a minimal setup without configuring persistent storage.

Interview questions

QWhat role does the database option play in Better Auth?

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.

QHow can Better Auth be connected to storage?

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.

QWhy configure a database for Better Auth?

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 adapters
  • Drizzle adapter
  • stateless session management
  • PostgreSQL
  • MySQL
  • SQLite

Source: Database. Checked 2026-10-15.