Deployment Setup

Verge Kit deploys to Cloudflare Workers with D1 by default. The Node.js + MySQL preset can be deployed on a classic VPS or any polatform that supports Node processes.

Run Project Checks

npm run verify

This command runs type checks, linting, tests, and the production build.

Add Worker Variables

Put non-secret Worker values in wrangler.jsonc:

{
  "vars": {
    "EMAIL_PROVIDER": "console",
    "BETTER_AUTH_URL": "https://example.com",
    "EMAIL_FROM": "VK <[email protected]>",
    "MAILGUN_DOMAIN": "mg.example.com",
  },
}

Each named Wrangler environment needs its own vars block.

See the Configuration Guide for the correct location of each value.

Add Deployed Secrets

Better Auth requires one stable secret:

npx wrangler secret put BETTER_AUTH_SECRET

Add the secret for the selected email provider:

npx wrangler secret put RESEND_API_KEY
npx wrangler secret put MAILGUN_API_KEY

Wrangler asks for each value. Do not put secret values in commands, shell history, or wrangler.jsonc.

For a named environment, include its name:

npx wrangler secret put BETTER_AUTH_SECRET --env production

List the configured secret names:

npx wrangler secret list
npx wrangler secret list --env production

Prepare D1

If the production database does not exist, create it:

npx wrangler d1 create vk

Add the returned database_id to the DB binding in wrangler.jsonc.

Apply the remote migrations:

npm run db:migrate:remote

For the first deployment, create a verified user with the admin role:

npm run init:admin -- --remote

Review Email Configuration

Make sure that EMAIL_PROVIDER matches the deployed environment.

For Cloudflare Email, add the EMAIL binding and use a verified sending domain.

For Resend or Mailgun, add the required API key secret. Use a verified sender or domain in EMAIL_FROM.

Deploy

Deploy through the project CI workflow, or run:

npx wrangler deploy

For a named environment, run:

npx wrangler deploy --env production

After deployment, do these checks:

  • Open the application.
  • Sign up and sign in.
  • Send verification and password-reset email.
  • Open each changed protected route.
  • Make sure that administrator access works.