Skip to main content
Recommended default: Supabase PostgreSQL for the database host, with Better Auth inside the app for authentication and sessions. This is the fastest, most supported path.
Recommended path: run pnpm bootstrap first. The setup wizard writes .env.local, generates BETTER_AUTH_SECRET, runs pnpm db:migrate, and can also walk you through Google OAuth and email-provider config. The tabs below are the manual equivalent.

The Mental Model

Here’s how the pieces fit together:
  • PostgreSQL + Drizzle = your data layer (schema, migrations, queries)
  • Better Auth = your auth layer (sessions, sign-in, OAuth, magic links)
  • Supabase = the recommended managed Postgres host
Better Auth runs inside your app. Supabase just hosts the database. You’re not locked into Supabase — any PostgreSQL provider that supports pgcrypto and pgvector will work.

Quick Setup

The fastest path. No OAuth, no magic links — just email and password.
1

Set your env vars

Add these to your .env.local:
NEXT_PUBLIC_APP_URL=http://localhost:3000
BETTER_AUTH_SECRET=your-secret-here
DATABASE_URL=postgresql://...
If you copy the connection string from Supabase, replace the literal [YOUR-PASSWORD] placeholder with your real database password before pasting.
2

Run migrations

pnpm db:migrate
3

Start the app

pnpm dev

What Better Auth Handles

  • Sign-in and session cookies
  • Email/password accounts
  • Google OAuth
  • Magic link and forgot password
  • Profile bootstrap via database hooks
Email/password works without an email provider. Magic link and forgot password need a real email provider plus auth-email config once you enable those flows.

What Drizzle Handles

  • Schema definition in lib/db/schema/*
  • SQL migration history in drizzle/*
  • App-side database access in lib/db/*
When you change lib/db/schema/*, generate a new SQL migration with pnpm db:generate.
The RAG/document search features depend on the pgvector extension. The repo enables it in drizzle/0000_better_auth_baseline.sql, so your database host must support CREATE EXTENSION vector.

Can You Use Another PostgreSQL Provider?

Yes. The main requirements are:
  • pgcrypto support
  • pgvector support
  • Standard Drizzle/Postgres features used by the schema
Supabase is the recommended default because it gives you managed PostgreSQL plus pgvector out of the box.

Auth Helpers in the Repo

The main server-side auth helpers live in lib/auth/server.ts. Here’s the pattern:
HelperUse When
getAuthContext()Auth is optional
requireUser()Server pages and layouts
requireApiUser()API routes
signOutCurrentSession()Logout flows

Verify It Works

Your auth and database setup is correct if you can:
  • Sign in on /auth
  • Reach /
  • See a profile row created for your user
  • Use at least one authenticated app flow