Railway

Deploy Next.js BetterAuth [Aug 26]

Next.js 16 + BetterAuth + Postgres SaaS starter with auth · Updated Aug 26

Deploy Next.js BetterAuth [Aug 26]

/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 .nvmrc and engines in package.json)

Getting Started

  1. Click Deploy on Railway
  2. In the deploy wizard, provide BETTER_AUTH_SECRET (or accept a generated value)
  3. Add a Postgres service — Railway injects DATABASE_URL automatically
  4. Open the generated domain and create your account at /sign-in

Next Steps

  • Add domain models — edit src/db/schema.ts, then run npm run db:generate and npm run db:migrate
  • Enable OAuth — add a social provider in src/lib/auth.ts and set the client ID/secret as variables
  • Custom domain — add one to your Railway service

License

MIT


Template Content

More templates in this category

View Template
NEW
Paperless-ngx
Document management with OCR on Railway with PostgreSQL and Redis

INAPP
1
View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
1
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5