Next.js on Vercel with Supabase: connection strings, DNS and variables

How a Vercel project and a Supabase database are joined for a Next.js SaaS: which connection string to use, the DNS records, and when to redeploy.

Simon, Founder of Shipyard

By · Founder of Shipyard

Vercel runs the app and Supabase holds the data. The two meet in exactly one place, a connection string in an environment variable, and that one place is where most of the trouble with this pair starts: the wrong port, a driver setting, or a variable that was changed without a new deployment.

This page covers that join, the domain records at Cloudflare, and the points where Vercel behaves differently from a host that keeps a server running. Email and payments are set up the same way as on Railway and are covered in that guide.

Why these two are a pair

In Shipyard's catalog Vercel comes without a database and without background workers, so choosing Vercel always means choosing a separate database. Supabase is the one Shipyard can set up for it today.

One condition comes before any setup. Vercel's terms limit the Hobby plan to "personal or non-commercial use". A product that takes payments belongs on a paid plan from the first day, so decide that before you connect a domain.

What gets created, and where

Shipyard uses eu-central-1 as the Supabase region when you do not give one. Pick the region nearest to where your Vercel functions run, because every query crosses that distance.

ProviderWhat is createdDetail worth knowing
GitHubA private repository with the Next.js appMust exist before the Vercel project
VercelOne project, framework set to Next.jsThe repository is linked when the project is created
SupabaseOne project in the organisation and region you nameThe database password is generated on your computer and kept in its keychain
CloudflareThe DNS zone and the records for the bare domain and wwwRecords are DNS only, not proxied

The order

  1. Domain and DNS zone at Cloudflare, active before anything else.
  2. Repository on GitHub, with the Vercel GitHub app installed on the account that owns it.
  3. Vercel project, created with the repository already linked. The API takes the link at creation, so a project made without it has to be connected by hand in its Git settings.
  4. Supabase project. A new project needs a minute or two before Postgres answers, so wait for its health check instead of deploying straight away.
  5. First production deployment, then the two domain names and their records.
  6. Variables, followed by a new deployment. On Vercel the second half of that sentence is not optional.

Supabase to Vercel: which connection string

Supabase offers three ways in, listed in the table below, and the right one depends on what is connecting.

Vercel functions are short-lived and open many connections, which is the case Supabase names for transaction mode. Shipyard does not build the string itself: it asks Supabase's Management API for the project's pooler connection string, puts in the password it generated, and writes the result to Vercel as DATABASE_URL. Look at the port in that value so you know which mode you have.

Transaction mode has one cost. On the shared pooler it does not support prepared statements, and Supabase tells you to switch them off in the driver, for example prepare: false in Postgres.js and Drizzle. An app that works locally against a direct connection and fails on Vercel with a prepared statement error has hit exactly this.

Migrations are the exception. Supabase recommends a direct connection for migrations and for pg_dump, so run those from your own machine or from CI with the direct string, not through the app's pooled one.

ConnectionHost and portNetworkMeant for
Directdb.<ref>.supabase.co, port 5432IPv6, or IPv4 with the paid add-onLong-running servers, migrations, backups
Shared pooler, session modeA pooler.supabase.com host, port 5432IPv4 on every planLong-running servers on IPv4-only networks
Shared pooler, transaction modeThe same pooler host, port 6543IPv4 on every planServerless and edge functions

Vercel and Cloudflare: an A record and a CNAME

Vercel configures a bare domain with an A record and a subdomain such as www with a CNAME. The values are not the same for everyone: Vercel's documentation says each project has its own CNAME target and tells you to use the values shown for your project, not ones copied from another. Shipyard reads the recommended values for your project from Vercel's domain configuration endpoint and writes those.

A third record appears only in one case. If the domain is already in use by another Vercel account, Vercel asks for a TXT record at _vercel on the bare domain to prove you may use it.

Keep Cloudflare's proxy off for these records. Vercel's own guide for Cloudflare users says to grey-cloud the record so that traffic goes straight to Vercel, and its note on reverse proxies lists what you get otherwise: two caches that do not know about each other, and stale pages after a deploy.

DNS records
A      example.com       <IPv4 address Vercel shows for the project>   DNS only
CNAME  www.example.com   <CNAME target Vercel shows for the project>   DNS only

Variables only reach new deployments

This is the difference from Railway that catches people. Vercel states that a change to environment variables is not applied to previous deployments, only to new ones. The site that is running keeps the values it was built with.

Shipyard therefore writes every variable for the Production and Preview environments and then starts a new production deployment from the linked repository. If you change a value by hand later, redeploy yourself.

Names that begin with NEXT_PUBLIC_ need a rebuild for a second reason. Next.js copies them into the browser bundle at build time, so the old value stays in the JavaScript your visitors download until the next build. Shipyard stores those as plain values and everything else as encrypted ones.

If Supabase also handles sign-in

With Supabase Auth chosen, three more variables are written: NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY and SUPABASE_SECRET_KEY. The publishable key is meant for the browser. The secret key bypasses every Row Level Security policy and must stay on the server. The Railway and Supabase guide goes through the sign-in settings, including the limit on sign-in emails that a new project starts with.

What goes wrong, and what it looks like

Start from this stack

The code below selects Vercel for hosting and Supabase for the database, with every other choice left on its default. Loading it changes nothing at any provider; the plan that follows shows each thing that would be created.

shipyard stack use S111000000000000

The setup article for each provider

Each provider in this guide has one article with its full steps. They are all listed on the integrations page.

Sources

Have this set up for you

Shipyard creates everything on this page on your own accounts, from your coding agent. Your keys stay in the keychain on your computer, and anything that costs money waits for your yes.

Pick your stack

Read next