
Deploy Next.js BetterAuth [Aug 26]
Next.js 16 + BetterAuth + Postgres SaaS starter with auth · Updated Aug 26
Just deployed
Just deployed
/var/lib/postgresql/data
Deploy and Host Next.js 16 + BetterAuth + Postgres on Railway
About Hosting
Railway provides a modern, streamlined platform for deploying web applications and databases. This template bundles a production-ready Next.js 16 application with BetterAuth authentication, Drizzle ORM, and a Postgres database — all configured to work together out of the box.
Why Deploy
Deploying this template gives you a complete SaaS starter in minutes, not days:
- Authentication included — email/password sign-up and sign-in with sessions persisted in Postgres, powered by BetterAuth (self-hosted, no vendor lock-in)
- Zero manual setup — Drizzle migrations run automatically during deployment via preDeployCommand
- Production-ready defaults — healthcheck endpoint for Railway monitoring, standalone output for an efficient container, and restart-on-failure policy
- Type-safe stack — Next.js 16, React 19, Drizzle ORM 0.45, TypeScript 5.7, Zod 4
Common Use Cases
- SaaS MVPs — launch a new product with auth and a database from day one
- Internal tools — secure dashboards and admin panels with user accounts
- Learning projects — a clean, modern reference for Next.js + BetterAuth + Drizzle
- Template for future apps — fork it and add your own domain models
Dependencies for
This template requires:
Deployment Dependencies
- PostgreSQL 16 — add the Postgres service in the Railway dashboard (or use your own connection string via
DATABASE_URL) - BETTER_AUTH_SECRET — generate one with
openssl rand -base64 32; the Railway deploy wizard will prompt you for it - Node.js 20+ (pinned via
.nvmrcandenginesinpackage.json)
Getting Started
- Click Deploy on Railway
- In the deploy wizard, provide
BETTER_AUTH_SECRET(or accept a generated value) - Add a Postgres service — Railway injects
DATABASE_URLautomatically - Open the generated domain and create your account at
/sign-in
Next Steps
- Add domain models — edit
src/db/schema.ts, then runnpm run db:generateandnpm run db:migrate - Enable OAuth — add a social provider in
src/lib/auth.tsand set the client ID/secret as variables - Custom domain — add one to your Railway service
License
MIT
Template Content
DATABASE_URL
BETTER_AUTH_SECRET
PGDATA
PGPORT
POSTGRES_DB
POSTGRES_USER
SSL_CERT_DAYS
RAILWAY_DEPLOYMENT_DRAINING_SECONDS