---
title: "Deploy Next.js BetterAuth [Aug 26]"
description: "Next.js 16 + BetterAuth + Postgres SaaS starter with auth · Updated Aug 26"
category: "Starters"
url: https://railway.com/deploy/nextjs-betterauth-postgres
---

# Deploy Next.js BetterAuth [Aug 26]

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

**[Deploy Next.js BetterAuth [Aug 26] on Railway](https://railway.com/template/nextjs-betterauth-postgres)**

- **Creator:** Marco Quintella's Projects
- **Category:** Starters

## Template content

### web

- **Source:** https://github.com/marco-quintella/nextjs-betterauth-postgres

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

## Documentation

# 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


## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/nextjs-betterauth-postgres
