Documentation

Deployment

Deploy Motoko Base to any Next.js-compatible platform, with a Vercel walkthrough as the recommended option.

Open inChatGPT (opens in a new tab)Claude (opens in a new tab)Cursor (opens in a new tab)Deploy Motoko Base to any Next.js-compatible platform, with a Vercel walkthrough as the recommended option.

Motoko Base is a standard Next.js application and can be deployed to any platform that supports Next.js — Vercel, Railway, Fly.io, Render, Docker on a VPS, AWS, Cloudflare, or self-hosted Node.

Requirements:

  • Node.js ≥ 22
  • pnpm (or translate scripts to your package manager)
  • Ability to set environment variables at build and runtime
  • PostgreSQL reachable from the host

Build and start commands:

pnpm install
pnpm build
pnpm start

Migrations run separately (not during next build):

pnpm db:migrate

Complete the Production Setup checklist before go-live.


Platform-agnostic steps

  1. Connect your repo to the host (or deploy a built artifact).
  2. Set environment variables from Production Setup.
  3. Run migrations against production Postgres (pnpm db:migrate — use a direct DB URL if the pooler blocks DDL).
  4. Build: pnpm build (Node 22+, install deps with pnpm install).
  5. Start: pnpm start (default port 3000 — configure PORT if your host requires it).
  6. Configure webhooks — Polar → {APP_URL}/api/billing/webhooks/polar when billing is enabled.
  7. Smoke test — sign up, verify email, open dashboard, test integrations you enabled.

Notes for any host

TopicGuidance
Serverless / edgeWorks — app uses standard App Router + Server Actions. Prefer Postgres pooler for DATABASE_URL.
Long-running serverWorks — same env vars and commands.
DockerMulti-stage build: install → pnpm build → run pnpm start with production env.
Preview/stagingUse separate env vars and OAuth/Polar sandbox credentials; optional BETTER_AUTH_TRUSTED_ORIGINS.
SecretsNever commit .env. Use the host's secret manager. Never expose server secrets on NEXT_PUBLIC_*.
Sentry source mapsSet SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT in the build environment.

Official Next.js deployment guide: nextjs.org/docs/app/getting-started/deploying


Vercel is the recommended option — zero-config Next.js hosting, preview deployments, and native support for the stack Motoko Base uses.

Vercel docs: vercel.com/docs

1. Import the project

  1. Push your repo to GitHub, GitLab, or Bitbucket
  2. Import the project in Vercel
  3. Framework preset: Next.js (auto-detected)
  4. Build command: pnpm build (Vercel detects pnpm from packageManager in package.json)
  5. Install command: pnpm install

2. Environment variables

In Project Settings → Environment Variables, add vars from Production Setup:

  • Production — all production values
  • Preview — staging/sandbox values (Polar sandbox, test OAuth apps, etc.)

At minimum for production:

DATABASE_URL=
BETTER_AUTH_SECRET=
BETTER_AUTH_URL=https://your-app.vercel.app
NEXT_PUBLIC_APP_URL=https://your-app.vercel.app
RESEND_API_KEY=
EMAIL_FROM=

Add integration vars as you enable them (Polar, R2, PostHog, Sentry, OAuth, OpenAI).

For Sentry source maps, also set SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT for the Production environment so they are available at build time.

3. Database migrations

Run migrations before the first production deploy (or from CI):

# Locally or CI — point DATABASE_URL at production (direct URL if needed)
pnpm db:migrate

Vercel does not run migrations automatically. Options:

  • Run manually from your machine against production DATABASE_URL
  • Add a CI step (GitHub Action) that runs pnpm db:migrate on deploy
  • Use Supabase migration tooling if you host Postgres there

4. Deploy

Push to your main branch — Vercel builds and deploys automatically.

After the first deploy:

  1. Update BETTER_AUTH_URL and NEXT_PUBLIC_APP_URL to your custom domain if you add one
  2. Update OAuth callback URLs and Polar webhook URL to match the live domain
  3. Redeploy if env vars changed

5. Custom domain

  1. Project Settings → Domains → add your domain
  2. Update DNS per Vercel instructions
  3. Set BETTER_AUTH_URL and NEXT_PUBLIC_APP_URL to https://yourdomain.com
  4. Update Google/GitHub OAuth and Polar webhook URLs
  5. Redeploy

6. Verify

  • Sign up → receive verification email (Resend)
  • Sign in → /dashboard loads
  • Optional: Polar checkout, R2 upload, PostHog events in dashboard, Sentry test error (pnpm build && pnpm start locally or check Issues after deploy)

Other platforms (brief)

PlatformApproach
RailwayConnect repo, set env vars, build pnpm build, start pnpm start, attach Postgres plugin
Fly.ioDockerfile or fly launch, set secrets via fly secrets set, run migrations via release command
RenderWeb Service, build pnpm install && pnpm build, start pnpm start
DockerNode 22 image, copy repo, pnpm install --frozen-lockfile && pnpm build, CMD pnpm start

Same env vars and migration step apply everywhere — only the host configuration differs.


Production Setup — Full pre-launch checklist.

Environment Variables — Complete env reference.