TheFocus.AI Engineering handbook

§ 07 · Platform recipes / Reference recipes/vercel.md

Deploy on Vercel

Preview parity, native environment delivery, and isolated data writes.

Procedure, not independent policy. Check the cited versions and verification limits before use.Markdown .md · GitHub ↗

Follow release guidance before changing a deployment.

Canonical pattern for Next.js apps on Vercel with GitHub previews, fnox-backed secrets, Neon, Vercel Blob, and Clerk. Reference implementation: the habitats repo (Next.js, fnox, Neon + Blob + Clerk). The maintained sync implementation is this repository's scripts/sync-secrets.mjs, not the former bulk-export task.

For remote-server / pi / tmux setup see handbook/development.md. For Clerk domain and OAuth rules see recipes/clerk.md. For the full fnox playbook see recipes/fnox.md. For CI, testing against previews, and failure notification see handbook/release.md and recipes/ci.md.

Defaults

ConcernStandard
HostVercel (GitHub integration)
Production branchmain → Production deployment
Other branches / PRsPreview deployments (*.vercel.app)
DatabaseNeon Postgres (DATABASE_URL pooled + DATABASE_URL_UNPOOLED when needed)
Object storageVercel Blob (BLOB_READ_WRITE_TOKEN)
AuthClerk — production-equivalent flows in Preview; production instance in Production; dev instance for local work
Secrets1Password vault → fnox → mise run vercel:sync → Vercel env store
Runtime on VercelNative Vercel env vars only — do not run fnox in the Vercel build or serverless runtime

One-time project setup

GitHub + Vercel

  1. Create a Vercel project linked to the GitHub repo.

  2. Settings → Git → Production Branch = main.

  3. Leave Preview Deployments enabled for non-main branches and pull requests.

  4. If the Next app is not at the repo root (e.g. app/ or web/):

    • Settings → General → Root Directory = that folder.

    • Enable including source files outside the root when using a pnpm workspace.

  5. Pin npm:vercel through mise; run mise install.

  6. Link the intended project/team explicitly using the pinned CLI's project and scope options. Keep .vercel/ gitignored; verify its project/team IDs against the committed sync target before using CLI deployment tasks.

vercel.json

Commit a minimal config next to the Next app (adjust path for monorepos):

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "framework": "nextjs"
}

Add crons only when the app needs them. Cron handlers must verify Authorization: Bearer $CRON_SECRET and stay on the public middleware allowlist.

Required mise tools and tasks

Pin Vercel CLI, Node and fnox via mise. recipes/fnox.md owns bootstrap, source-profile semantics and the common sync contract. Configure the following consuming-project tasks; they are not deployment tasks for this standards website:

TaskPurpose
mise run setupGet a checkout ready: a token that reads the project vault, then a secrets check (recipes/fnox.md)
mise run secrets:check / secrets:listResolve required keys / list declarations without values
mise run vercel:syncRun node scripts/sync-secrets.mjs --config secret-sync.json; forward explicit --target and optional --apply
mise run vercel:deployTrigger the approved CI/Git production deployment for the recorded project/team
mise run vercel:previewTrigger the recorded project's preview build; not a production release

Configure and review the target

  1. Copy scripts/sync-secrets.mjs and adapt templates/secret-sync.example.json as secret-sync.json at the consuming repo root. Keep only its Vercel targets.

  2. Replace prj_REPLACE and team_REPLACE with IDs verified in project/team settings. Each target explicitly selects preview, production, or development; there is no default production destination.

  3. Review each keys mapping and fnox source file/profile. Shared profile runtime and shared keys are intentional in the example. Add database and URL overrides only where required; do not export every key in the vault.

  4. Create an expiring project-scoped Vercel access token [3], with an owner and renewal date. Inject it into the authorized sync job as VERCEL_SYNC_TOKEN (or the configured tokenEnv), alongside the source's project-vault token. Team scope is broader, not equivalent. Do not use a full-account token by default.

  5. Run the offline tests, inspect dry-run output, then authorize writes. Do not run sync inside fnox exec or a shell hook that resolves secrets before dry-run.

The direct commands, before adding the forwarding mise task, are:

node scripts/sync-secrets.mjs --config secret-sync.json --target vercel-preview
# Authorized writes only after reviewing the plan:
node scripts/sync-secrets.mjs --config secret-sync.json --target vercel-preview --apply
node scripts/sync-secrets.mjs --config secret-sync.json --target vercel-production --apply

The script uses GET /v10/projects/{projectId}/env?teamId=...&decrypt=false for a preflight inventory [1], then one POST /v10/projects/{projectId}/env?teamId=...&upsert=true per key [2]. Each body contains one explicit target scope; values travel as JSON in HTTPS, never --value arguments. There is no remove-before-add window. A 201 alone is insufficient: the tool also checks failed and the returned key/scope/type.

All scopes use type: sensitive and visibility: secret. Vercel's current Config/Secret documentation [4] explicitly allows Secrets in Development, reversing the older Preview/Production-only restriction. Secret values are write-only; an empty/redacted pull is not proof that a value was stored empty or that it is correct. Confirm behavior in a newly built deployment.

Vercel's optional Separate Production Secret Values team policy can forbid sharing a value between Production and other scopes [4]. Shared runtime keys remain this guide's default where permitted. If that policy is enabled, the write fails rather than silently switching source or weakening visibility; document the provider constraint and obtain approval for the needed mapping.

For managed keys, preflight refuses shared multi-scope records, branch/custom overrides, duplicate entries, integration-owned records, and incomplete inventories. Review and separate those records deliberately before adopting this tool; do not delete an old value as part of a blind retry. This implementation manages ordinary scope-wide variables, not custom environments or branch-specific overrides. Serialize jobs and avoid dashboard edits while syncing: preflight is not a lock.

On failure, stop the deploy. Confirmed earlier writes remain; the current write may have landed despite a timeout or invalid response. Inspect remote state before retrying. The script does not roll back, delete unrelated variables, retry automatically, or claim all-or-nothing behavior.

fnox.toml

Declare every runtime env var the app needs. Item title in 1Password = env var name. Non-secrets may use default = "...".

Minimum set for a typical app:

Env varRole
DATABASE_URLNeon pooled connection string
DATABASE_URL_UNPOOLEDNeon direct URL (migrations, LISTEN/NOTIFY, session features)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYClerk publishable key
CLERK_SECRET_KEYClerk secret key
CLERK_WEBHOOK_SECRETSvix signing secret (if webhooks are used)
BLOB_READ_WRITE_TOKENVercel Blob read/write token
CRON_SECRETBearer for Vercel Cron (if crons exist)
NEXT_PUBLIC_APP_URLCanonical public URL for the environment

Optional but common: AI_GATEWAY_API_KEY, app-specific secrets, JWT template name as a fnox default.

Keep a committed .env.example that lists the same keys with comments for local / Preview / Production — no real values.

Environment matrix

Vercel has three scopes. Map them deliberately, starting Preview from the production configuration rather than a reduced development configuration:

Local / DevelopmentPreview (PR / branch)Production
Triggerpnpm dev / vercel devPush to non-main or open PRPush to main (or vercel:deploy)
Sync targetAdd explicit vercel-development target if needed--target vercel-preview--target vercel-production
1PasswordProject vault or isolated dev sourceShared project vault; isolated source only where neededProject vault
NeonDev branch or localStaging / preview branchProd branch
ClerkDev instance pk_test_ / sk_test_Production-equivalent auth; document provider/domain constraintsProduction instance pk_live_ / sk_live_
BlobDev store tokenSame integration; isolate writes that could harm production objectsProd store token
NEXT_PUBLIC_APP_URLhttp://localhost:3000Preview URL or branch aliasCustom domain
CLERK_AUTHORIZED_PARTIESLocal originApproved preview origin or stable alias; same origin checksLocked to the prod origin

Parity, with explicit exceptions: handbook/secrets.md makes production behavior the default, not separate keys. Shared runtime credentials are appropriate when their permissions suit both targets; keep preview writes off the production database. Record each differing setting, its reason, and what the preview cannot verify. The sync task selects sources and allowed keys explicitly; the destination flag alone does not establish that mapping.

GitHub branch previews

  1. Connect the repo in the Vercel dashboard (Git integration).

  2. Every push to a non-production branch and every PR gets a Preview deployment built with the Preview env scope.

  3. After changing Preview secrets: dry-run, then mise run vercel:sync -- --target vercel-preview --apply; redeploy to pick up values.

  4. NEXT_PUBLIC_* vars are baked at build time. Changing them requires a new deployment through the recorded project's CI/Git pipeline.

  5. Allow preview origins where the framework requires it (e.g. Next server actions allowedOrigins including *.vercel.app).

Neon

  • The Neon ↔ Vercel integration can provision pooled/direct connections. Give each variable one delivery owner: either record an integration-managed exception or transfer it deliberately to the 1Password-backed sync mapping. Do not have the integration and this script overwrite each other's values.

  • App queries: pooled URL. Migrations / LISTEN / session features: unpooled.

  • Preview isolation: a Neon branch (or separate project) whose connection strings are mapped to the Preview Vercel scope; this does not require a separate vault. Keep schema and database behavior aligned with production, apart from the change under test.

  • Run migrations through an authorized cloud operational job against the explicit target URL, after any required approval. Do not depend on a laptop or use a Vercel build as an implicit destructive-migration step.

Map the migration job's explicit fnox profile to the intended direct database reference and execute its migration command through fnox. Keep tracing disabled; never print the connection string as a diagnostic.

Vercel Blob

  1. Create a Blob store in the Vercel project (or reuse per-environment stores).

  2. Put BLOB_READ_WRITE_TOKEN in the matching 1Password vault.

  3. Sync with vercel:sync for each env scope that needs storage.

  4. Prefer private blobs; serve through authenticated app routes (signed URL or stream), not public world-readable URLs for client data.

  5. Health checks should report whether the blob token is present (boolean), not the token value.

Clerk: production and preview

Instance setup and the publishable-key diagnostic live in recipes/clerk.md; use that diagnostic for both live and test keys rather than a live-prefix-only decoder. A development instance still uses client-specific OAuth applications under handbook/sign-in.md; Preview aims to exercise production authentication under handbook/secrets.md, not inherit development shortcuts automatically.

PreviewProduction
Instance / keysSelect a supported preview domain/instance setup; share runtime keys where appropriateProduction instance on the client custom domain; pk_live_… / sk_live_…
Social OAuthSame providers and client-specific setup as productionThis client's Google/Microsoft apps; never another client's (see recipes/clerk.md)
DomainsConfigure the actual preview origin and callback URLs; document required differencesCustom domain + Clerk CNAMEs (DNS-only / grey cloud on Cloudflare)
authorizedPartiesApproved preview origin or stable branch alias; retain origin checksLock to https://<prod-host>
WebhooksSame events and handlers at the preview endpoint; isolate harmful downstream effectsProd URL + CLERK_WEBHOOK_SECRET in Production scope
MiddlewareSame auth checks and public-route exceptions; no silent auth bypassPublic: sign-in/up, health, cron, webhooks; never put DEV_AUTH_BYPASS in Production

Verify Clerk's supported domains and redirects before selecting shared keys; do not assume copying live keys makes an arbitrary preview URL work. If a provider constraint requires a development-only fallback, document what it leaves unverified. Clerk's shared development OAuth credentials do not satisfy the client-isolation rule, even when a login succeeds.

Never put pk_test_ / sk_test_ in Vercel Production. The #1 prod outage pattern is shipping the dev instance to the live domain.

Practical sync model:

  1. Map shared runtime keys and justified overrides to each Vercel scope.

  2. Keep preview database writes on a separate branch; scope Blob writes and webhook effects so testing cannot damage production data.

  3. mise run vercel:sync -- --target vercel-preview reviews that mapping without resolving values.

  4. Select vercel-production explicitly for production; add --apply only after approval.

A shared project vault is compatible with this model. A blind export of its contents is not: sync only each target's required keys (handbook/secrets.md).

Daily operations

For production, record the verified candidate and required release approval before triggering the CI deployment (handbook/release.md). No separate staging environment is required; a Git-triggered release still has that gate.

# Rotate the value through 1Password's secure UI, not shell arguments.
# Review then apply the explicit production target.
mise run vercel:sync -- --target vercel-production
mise run vercel:sync -- --target vercel-production --apply
# Trigger the approved CI/Git deployment for this project.
# Review key names/scopes in the project's dashboard, then smoke-test.
curl --fail --silent --show-error "https://<host>/api/health"

An inventory confirms names and scopes, not that values work. Test actual database/auth/storage operations without exposing credentials in logs.

Troubleshooting

SymptomCheck
No Next.js version detectedRoot Directory points at the Next.js app, not the monorepo root
No Output Directory named publicFramework Preset is Next.js; minimal vercel.json is next to the app
Empty-looking sensitive value on pullSensitive values are write-only; verify a rebuilt app rather than replacing them with empty strings
Quotes/newlines corruptedUse the maintained JSON-based sync, not shell/dotenv line splitting
Profile mismatchUnset the ambient FNOX_PROFILE or choose the matching named target; do not change only the destination

Do not install fnox in the Vercel build or store only its bootstrap token there. Native environment delivery avoids a 1Password request at every cold start; already-deployed functions do not depend on a later sync succeeding.

Health and cron

  • Expose /api/health (or equivalent) that reports booleans for DB / Blob / Clerk config without leaking secrets.

  • Cron routes: declare in vercel.json, protect with CRON_SECRET, exclude from Clerk auth.

  • Long jobs: set maxDuration / Fluid Compute as needed; document in the app.

Anti-patterns

  • Manual dashboard-only secrets with no fnox / 1Password source of truth.

  • fnox exec (or installing fnox) as the Vercel build command.

  • Dev Clerk keys in Production; live keys committed to .env or the repo.

  • One Neon database shared by Preview and Production with write access from both.

  • Syncing the entire monorepo vault into a Vercel project that only needs a subset (review vercel env ls after sync).

  • Changing NEXT_PUBLIC_* and expecting running deployments to pick it up without a rebuild.

  • Relying on Supabase-as-default for new Focus projects — prefer Neon unless the client already standardized on Supabase (document the exception).

New project checklist

  • [ ] Vercel project linked to GitHub; Production branch main; Preview on

  • [ ] Root Directory + vercel.json "framework": "nextjs"

  • [ ] npm:vercel in mise; vercel link; .vercel/ gitignored

  • [ ] Dedicated 1Password vault(s); fnox.toml; mise run setup

  • [ ] vercel:sync / vercel:deploy / vercel:preview tasks

  • [ ] Neon: pooled + unpooled URLs; Preview branch planned

  • [ ] Blob token(s) in fnox

  • [ ] Clerk: production instance in Production; production-equivalent auth in Preview

  • [ ] Preview configuration differences have a reason and documented testing limits

  • [ ] .env.example matches fnox keys; health endpoint exists

  • [ ] Explicit sync target reviewed and applied; deployed runtime and key/scope inventory verified

  • [ ] Custom domain + Clerk DNS per recipes/clerk.md when going live

Verification and primary sources

Checked 2026-10-30: reachable primary API documentation and offline simulated adapter tests (node --test tests/test-secret-sync.mjs). No real provider credential was read, no live write or deployment was performed, and these tests do not establish live permission or account-specific API behavior. Before adoption, an authorized operator verifies a disposable project, exact scope isolation, sensitive-variable behavior, and runtime delivery.

[1] Vercel, environment inventory API.

[2] Vercel, create/upsert environment variables.

[3] Vercel, access token scope and expiry.

[4] Vercel, Config/Secret variables and separation policy.