Example Docs

Database

Better Auth uses your existing database — no proprietary backend required. It supports PostgreSQL, MySQL, SQLite, and MongoDB through built-in adapters.

Supported Databases

DatabaseAdapterORM Support
PostgreSQLpostgresqlPrisma, Drizzle, raw SQL
MySQLmysqlPrisma, Drizzle, raw SQL
SQLitesqlitePrisma, Drizzle, better-sqlite3
MongoDBmongodbMongoose

Configuration

Direct Connection

export const auth = betterAuth({
  database: {
    provider: "postgresql",
    url: process.env.DATABASE_URL,
  },
});

With Prisma

import { PrismaClient } from "@prisma/client";
import { prismaAdapter } from "better-auth/adapters/prisma";

const prisma = new PrismaClient();

export const auth = betterAuth({
  database: prismaAdapter(prisma),
});

With Drizzle

import { drizzle } from "drizzle-orm/node-postgres";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

const db = drizzle(process.env.DATABASE_URL);

export const auth = betterAuth({
  database: drizzleAdapter(db),
});

Schema

Better Auth creates and manages these tables automatically:

user

ColumnTypeDescription
idstringPrimary key
namestringUser's display name
emailstringUnique email address
emailVerifiedbooleanWhether email is verified
imagestring?Profile image URL
createdAtdatetimeAccount creation timestamp
updatedAtdatetimeLast update timestamp

session

ColumnTypeDescription
idstringPrimary key
userIdstringForeign key → user
tokenstringSession token (hashed)
expiresAtdatetimeWhen the session expires
ipAddressstring?Client IP address
userAgentstring?Client user agent

account

ColumnTypeDescription
idstringPrimary key
userIdstringForeign key → user
providerIdstringAuth provider (e.g., "google")
accountIdstringProvider-specific user ID
accessTokenstring?OAuth access token
refreshTokenstring?OAuth refresh token

verification

ColumnTypeDescription
idstringPrimary key
identifierstringWhat's being verified (email)
valuestringVerification token
expiresAtdatetimeToken expiry

Migrations

Automatic Migrations

Better Auth can automatically create and update tables:

npx @better-auth/cli migrate

Generate Migration Files

If you prefer to review migrations before applying:

npx @better-auth/cli generate

This creates SQL files you can review and apply manually.

When using Prisma, run npx @better-auth/cli generate --prisma to generate Prisma schema additions instead of raw SQL.

Custom Fields

You can extend the default schema with custom fields:

export const auth = betterAuth({
  user: {
    additionalFields: {
      role: {
        type: "string",
        defaultValue: "user",
      },
      bio: {
        type: "string",
        required: false,
      },
    },
  },
});

These fields are automatically added to the user table and included in the session user object.