Better Auth supports any database through adapters. Use this guide when you need full control over your database setup or can't use NuxtHub.
| Scenario | Recommended |
|---|---|
| Quick start, managed infra | NuxtHub |
| OAuth-only, no persistence | Database-less Mode |
| Existing database, custom setup | This guide |
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
import { drizzle } from 'drizzle-orm/node-postgres'
const db = drizzle(process.env.DATABASE_URL!)
export default defineServerAuth({
database: drizzleAdapter(db, { provider: 'pg' }),
emailAndPassword: { enabled: true },
})
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export default defineServerAuth({
database: prismaAdapter(prisma, { provider: 'postgresql' }),
emailAndPassword: { enabled: true },
})
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { kyselyAdapter } from 'better-auth/adapters/kysely'
import { Kysely, PostgresDialect } from 'kysely'
import { Pool } from 'pg'
const db = new Kysely({
dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) }),
})
export default defineServerAuth({
database: kyselyAdapter(db, { dialect: 'postgres', type: 'pg' }),
emailAndPassword: { enabled: true },
})
You must create the required tables manually. Better Auth provides a CLI to generate schemas:
npx better-auth generate
This generates migration files for your adapter. Apply them with your database tool.
Store your connection string securely:
DATABASE_URL="postgresql://user:password@localhost:5432/myapp"