Deploy to Vercel
Zero-configuration deployment to Vercel with Node 24 functions, static headers and image optimisation.
Vercel is the primary deployment target for this repository.
-
Import the repository at vercel.com/new. Vercel detects Astro and pnpm automatically. Leave the build command as
astro build;DEPLOY_TARGETis inferred fromVERCEL=1. -
Add the environment variables from
.env.examplein Project → Settings → Environment Variables. At minimum:DATABASE_URL,DATABASE_AUTH_TOKEN,BETTER_AUTH_SECRETandBETTER_AUTH_URL(a full URL such ashttps://my-site.vercel.app). If you add Turso through the Vercel Marketplace it setsTURSO_DATABASE_URLandTURSO_AUTH_TOKENinstead, which the template reads as well.SITE_URLis optional: when it is unset the build uses the production URL Vercel injects (VERCEL_PROJECT_PRODUCTION_URL). None of these variables are needed to build, so you can also add them after the first deployment and redeploy. -
Create the tables: add the database URL and token as GitHub Actions secrets (
DATABASE_URLandDATABASE_AUTH_TOKEN, or the sameTURSO_*names the integration uses) and run the Migrate database workflow (see the database guide). Vercel’s environment variables are not visible to GitHub Actions, so the secrets must be added in the repository even when the integration already set them on Vercel. Until the workflow has run, sign-up and the contact form fail because the tables do not exist. -
Deploy. Every pull request gets a preview deployment; preview hostnames are trusted by Better Auth automatically through
VERCEL_URLandVERCEL_BRANCH_URL.
What the adapter configures#
vercel({ imageService: true, staticHeaders: true });
- Node version. Vercel reads
"engines": { "node": "24.x" }frompackage.json. - Static headers. The Content Security Policy for prerendered pages is written to the Build
Output configuration instead of a
<meta>tag. - Security headers.
integrations/security-headers.tsprepends a route to.vercel/output/config.jsonthat applies the headers fromconfig/security-headers.tsto every path. - Images.
<Image>and<Picture>use Vercel Image Optimization at runtime.
Optional extras#
- Enable Vercel Web Analytics by setting
PUBLIC_ANALYTICS=vercel; the@vercel/analyticsAstro component is rendered only when this is set, and its beacons are same-origin so the CSP needs no change. - Turn on ISR for on-demand pages with
vercel({ isr: { expiration: 60 } })if you add server-rendered pages that can be cached. - Store the database with the Turso integration from the Vercel Marketplace, which injects
TURSO_DATABASE_URLandTURSO_AUTH_TOKEN; no renaming is needed.
Custom domains#
After adding a domain in Vercel, VERCEL_PROJECT_PRODUCTION_URL switches to it automatically.
Update BETTER_AUTH_URL and siteConfig.url (or set SITE_URL), then redeploy so canonical
links, the sitemap and OAuth callback URLs use the final host.