How to deploy Ostiary on Vercel with Neon Postgres
Deploy Ostiary, the open-source identity provider, on Vercel with Neon Postgres: environment variables, the first admin, the admin console, local setup.
Ostiary is a self-hosted identity provider, so the first question is where to run it. The shortest path is the one the project is built for: a Vercel template that provisions a Neon Postgres database and applies the migrations during the build. This guide walks through that path step by step, then covers the optional admin console, running Ostiary on your own machine, and what changes when you host it somewhere other than Vercel.
Everything here comes from the README and the configuration reference. If you are still deciding whether to run your own identity provider, start with Ostiary as a self-hosted Auth0 alternative.
What you need
- A Vercel account. The Deploy button creates the project and a Neon Postgres database for you.
- A Resend account, to send verification emails: an API key and a sender address on a domain verified in Resend.
- An email address for the first admin.
That is all. Ostiary is two Next.js apps and a shared core in one repository: apps/auth (sign-in, sign-up, consent, the OIDC endpoints and the account dashboard) and apps/admin (the optional admin console). You deploy the auth app first.
Step 1: deploy the auth app
Click Deploy with Vercel in the README or on the home page. Vercel clones the repository, creates a Neon Postgres database, and asks for four environment variables:
| Variable | What to put there |
|---|---|
BETTER_AUTH_SECRET | 32+ random characters, for example from openssl rand -base64 32 |
ADMIN_EMAILS | Your email address, so your account becomes an admin when you sign up and verify it |
RESEND_API_KEY | An API key from Resend |
RESEND_FROM | The sender, on a domain verified in Resend |
The database connection string, DATABASE_URL, is set by the Neon integration. The build applies the database migrations before building the app, so there is no separate migration step to run.
Neon suspends an idle database and wakes it on the next connection. While it starts, a new connection can fail; Ostiary retries it up to 3 times within 12 seconds instead of answering with an error. Only the connection is retried, never a query, so nothing runs twice.
Keep BETTER_AUTH_SECRET somewhere safe. It also encrypts stored secrets, such as social provider credentials, so changing it later means entering them again.
Step 2: sign up as the first admin
When the build finishes, open your deployment and sign up with the address you put in ADMIN_EMAILS, then open the verification link sent to it. The account becomes an admin once the address is verified. Signing up with a social provider works too when the provider reports the address as verified; SSO never grants the admin role.
Before you use the admin console, it asks you to turn on two-factor authentication. That is the REQUIRE_ADMIN_2FA setting, true by default: an admin without two-factor authentication is sent to set it up and cannot use the console or the admin endpoints until then.
Step 3 (optional): deploy the admin console
The admin console is a second app in the same repository, deployed as a second Vercel project. The README has a separate Deploy button for it. It uses the same database and secret, and needs to know both public URLs:
| Variable | Value |
|---|---|
DATABASE_URL | The same as the auth app |
BETTER_AUTH_SECRET | The same as the auth app |
AUTH_APP_URL | The auth app's URL |
ADMIN_APP_URL | This app's URL |
RESEND_API_KEY, RESEND_FROM | The same Resend settings, to send emails |
To show an "Admin" link in the account menu of the auth app, set NEXT_PUBLIC_ADMIN_APP_URL there.
One sign-in for both apps: COOKIE_DOMAIN
By default each app keeps host-only cookies, so the admin console needs its own sign-in. For a single sign-in across both, give them subdomains of one domain (for example auth.example.com and admin.example.com) and set COOKIE_DOMAIN=.example.com on both.
Read the COOKIE_DOMAIN section first. Browsers then send the session cookie to every host under that domain, and any of those hosts can set cookies for the whole domain. Only use a domain where every subdomain runs code you trust: no user-generated sites, no third-party SaaS on a CNAME, no forgotten DNS records. The security guide recommends a dedicated parent domain for identity, such as auth.example.com and admin.auth.example.com with COOKIE_DOMAIN=.auth.example.com.
Connect your first app
Ostiary is a standard OpenID Connect provider. Register a client in the admin console under Applications, then point your app at the discovery document:
https://<your-ostiary-domain>/api/auth/.well-known/openid-configuration
The issuer is https://<your-ostiary-domain>/api/auth. Any OIDC library works with the issuer, a client ID and a secret, and the provider supports PKCE for the authorization code flow. The protocol side, from scopes for your APIs to signing key rotation, is covered in running an OpenID Connect provider on Better Auth.
Settings worth knowing
The configuration reference lists every variable. A few you are likely to reach for early:
CRON_SECRET: 16+ characters, needed for webhooks. It protects/api/cron/webhooks, which retries failed webhook deliveries; Vercel Cron sends it.CAPTCHA_PROVIDER,CAPTCHA_SITE_KEY,CAPTCHA_SECRET_KEY: an optional captcha (Cloudflare Turnstile, hCaptcha or reCAPTCHA v2) on sign-up, password sign-in, password reset and sign-in codes. Set all three or none, before building.OAUTH_API_AUDIENCESandOAUTH_API_SCOPES: APIs and scopes registered at build time, for example to provision a new instance. You can also manage them in the console.VERCEL_ANALYTICS:trueadds Vercel Web Analytics to the app (turn it on in the Vercel project too). Page views are sent without query strings or fragments.
Most other settings, such as social sign-in providers, self-registration for MCP clients and signing key rotation, live in the admin console and need no redeploy.
Run Ostiary locally
Requirements: Node.js 20+, pnpm 11 and a Postgres database. The example environment file suggests a local Postgres in Docker (docker run -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:17). Then:
pnpm install
cp apps/auth/.env.example apps/auth/.env.local # fill in DATABASE_URL and BETTER_AUTH_SECRET
cp apps/admin/.env.example apps/admin/.env.local # same DATABASE_URL and BETTER_AUTH_SECRET
pnpm db:migrate
pnpm dev:auth # http://localhost:3000
pnpm dev:admin # http://localhost:3001
Without Resend configured, development prints verification and reset links, and sign-in codes, to the console, so you can sign up without sending email.
Hosting elsewhere: tell Ostiary where the client IP is
Ostiary runs on any Node host with any Postgres. One setting matters as soon as you leave Vercel: the client IP address. Rate limits, the IP stored with sessions, the audit log and the sign-in history all depend on it.
- On Vercel there is nothing to set: Vercel overwrites
x-forwarded-forwith the client's address. - Off Vercel, Ostiary trusts no header unless you set
IP_ADDRESS_HEADERSorTRUSTED_PROXIES. Behind Cloudflare,IP_ADDRESS_HEADERS=cf-connecting-ip. Behind nginx, a load balancer or several proxies that append tox-forwarded-for, setTRUSTED_PROXIESto their addresses (for example10.0.0.0/8).
With neither set, every client shares one rate-limit counter per endpoint, so a busy site will see 429 responses for everyone, and the apps log a warning at startup. The Client IP section of the security guide covers every setup.
For your load balancer or uptime monitor, both apps answer GET /api/health: 200 when the app and its database respond within 3 seconds, 503 otherwise. The Docker images' HEALTHCHECK uses the same endpoint.
Next steps
- Turn on passkeys for your users and read how they work in passkeys in a self-hosted identity server.
- Add enterprise single sign-on for business customers: SAML SSO and organizations for B2B apps.
- Let MCP clients register themselves, safely: OAuth for MCP clients.
Want to see the result before deploying? The live demo at demo.ostiary.dev runs the same sign-in screens.