Deploy on Vercel
Deploy Ostiary on Vercel with a Neon Postgres database, add the admin console as a second project, and put both on your own domain.
On Vercel, Ostiary is two projects from the same repository, sharing one database and one secret:
| Project | Root directory | What it serves |
|---|---|---|
Auth app (ostiary) | apps/auth | Sign-in pages, the OIDC provider, the account dashboard. Its build applies the migrations. |
Admin console (ostiary-admin), optional | apps/admin | The admin console. It has no sign-in page of its own: it reads the session the auth app created. |
You need a Vercel account, a Resend account for emails, and, for the admin console, a domain you control.
Deploy the auth app
-
Click Deploy with Vercel in the README. Vercel copies the repository to your Git account, creates the project with
apps/authas its root directory, and adds a Neon database, which setsDATABASE_URL. -
Fill in the variables it asks for:
Variable Value BETTER_AUTH_SECRET32 or more random characters: openssl rand -base64 32. Keep it: it also encrypts stored provider and webhook secrets.ADMIN_EMAILSYour email address, so your account becomes an admin when you sign up and verify it. RESEND_API_KEY,RESEND_FROMSee Set up email. CRON_SECRET16 or more random characters: openssl rand -base64 24. Protects the daily housekeeping job; see Add the daily housekeeping job. -
Wait for the build. It runs, from
apps/auth/vercel.json:pnpm --filter @ostiary/core db:migrate && pnpm --filter @ostiary/core db:seed && next builddb:migrateapplies new database migrations anddb:seedregisters the APIs fromOAUTH_API_AUDIENCES(see Protect an API). Both are safe to run on every build. -
Open the deployment, sign up with the address in
ADMIN_EMAILSand open the verification link you receive. The account becomes an admin once its address is verified. Signing up with a social provider works too, when the provider reports the address as verified; enterprise SSO never grants the admin role.
Warning: Every build migrates the database its
DATABASE_URLpoints to, preview deployments included. If previews share the production database, a preview of a newer version migrates production. Give previews their own database (Neon branches) or turn previews off.
Add the daily housekeeping job
apps/auth/vercel.json declares a Vercel Cron job that calls /api/cron/webhooks every day at 04:00 UTC. It retries webhook deliveries that are due, deletes deliveries older than 30 days, and deletes sign-in events older than AUTH_EVENT_RETENTION_DAYS (90 by default).
The route answers 401 to every call without CRON_SECRET, which the Deploy button asks for. Vercel Cron sends Authorization: Bearer $CRON_SECRET by itself; there is nothing else to set up.
If the project was created without it (an older version of the button, or a project created by hand):
- Generate a secret:
openssl rand -base64 24(16 characters at least). - In the auth project, open Settings > Environment Variables and add
CRON_SECRETwith that value. - Redeploy.
Set up email
Ostiary sends verification links, password reset links, sign-in codes and invitations through Resend. In production both apps refuse to build or start without RESEND_API_KEY and RESEND_FROM.
-
In Resend, add and verify your domain (for example
example.com). -
Create an API key with sending access.
-
Set, in every project:
RESEND_API_KEY=re_... RESEND_FROM="Ostiary <auth@example.com>" # a sender on the verified domain
If emails do not arrive, the function logs show [email] Resend ... error: with Resend's message. Troubleshooting has more.
Use your own domain
Choose the final address of the auth app early. It is the OIDC issuer your apps are configured with (https://auth.example.com/api/auth), and passkeys are bound to its hostname: moving to another domain later means reconfiguring every app, and users' passkeys stop working.
- In the auth project, open Settings > Domains and add
auth.example.com. - Set
AUTH_APP_URL=https://auth.example.com. Without it, Ostiary uses the project's production domain as Vercel reports it (VERCEL_PROJECT_PRODUCTION_URL); setting it removes any doubt. - Redeploy.
Add the admin console
The admin console is a second Vercel project on the same repository. It has no sign-in page: it sends you to the auth app to sign in, then reads the session cookie. So both apps must be subdomains of one domain, with COOKIE_DOMAIN set to that domain. *.vercel.app addresses cannot share cookies, so the admin console needs your own domain.
Warning: With
COOKIE_DOMAIN=.example.com, browsers send the session cookie to every host underexample.com. Read COOKIE_DOMAIN first, and prefer a dedicated domain for identity, such asauth.example.comandadmin.auth.example.comwithCOOKIE_DOMAIN=.auth.example.com.
-
Click the second button, Deploy the admin console, in the README. It creates a project with
apps/adminas its root directory. -
Fill in its variables:
Variable Value DATABASE_URLThe auth project's value (Settings > Environment Variables). BETTER_AUTH_SECRETThe same as the auth project. AUTH_APP_URLhttps://auth.example.comADMIN_APP_URLhttps://admin.example.comRESEND_API_KEY,RESEND_FROMThe same as the auth project. -
Add
COOKIE_DOMAIN=.example.com. If you setREQUIRE_ADMIN_2FAon the auth project, set the same value here. -
In the admin project, add the domain
admin.example.com(Settings > Domains) and redeploy. -
In the auth project, add these variables, then redeploy it:
COOKIE_DOMAIN=.example.com ADMIN_APP_URL=https://admin.example.com # lets sign-in send you back to the console NEXT_PUBLIC_ADMIN_APP_URL=https://admin.example.com # built into the pages: needs a new build -
Open
https://admin.example.com. Sign in on the auth app if asked. The first time, it asks you to turn on two-factor authentication on your account dashboard; then Go to the admin console.
The admin console's build does not migrate the database. When you upgrade, deploy the auth project first.
Optional settings
| Variable | Project | Effect |
|---|---|---|
VERCEL_ANALYTICS=true | Both | Adds Vercel Web Analytics. Also turn it on in the project's Analytics tab. Page views are sent without query strings. |
CAPTCHA_PROVIDER, CAPTCHA_SITE_KEY, CAPTCHA_SECRET_KEY | Auth | Captcha on sign-up, password sign-in, password reset and sign-in codes. Set all three, then redeploy: the provider is built into the pages. |
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET | Both | GitHub sign-in from the environment. Every other provider is set up in the admin console. |
Leave IP_ADDRESS_HEADERS and TRUSTED_PROXIES empty: on Vercel, Ostiary reads the client IP from x-forwarded-for, which Vercel sets. Configuration lists every variable.
Note: Vercel Functions accept request bodies up to 4.5 MB. A user import file larger than that fails on Vercel, even though Ostiary accepts files up to 10 MB: split it into several files.
Upgrade
The Deploy button made a copy of the repository in your Git account. To upgrade:
- Read the changelog for the versions you skip.
- Merge the new version of
florianamette/ostiaryinto your copy and push. Vercel builds both projects. - Make sure the auth project's build, which migrates the database, finishes before the admin console's deployment goes live.
Related
- Quickstart: run Ostiary locally first.
- Self-hosting: Docker Compose on your own server instead.
- Connect an app: register your first app.
- Security: what to review before going live.