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.
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.
| Provider | What is created | Detail worth knowing |
|---|---|---|
| GitHub | A private repository with the Next.js app | Must exist before the Vercel project |
| Vercel | One project, framework set to Next.js | The repository is linked when the project is created |
| Supabase | One project in the organisation and region you name | The database password is generated on your computer and kept in its keychain |
| Cloudflare | The DNS zone and the records for the bare domain and www | Records are DNS only, not proxied |
The order
- Domain and DNS zone at Cloudflare, active before anything else.
- Repository on GitHub, with the Vercel GitHub app installed on the account that owns it.
- 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.
- Supabase project. A new project needs a minute or two before Postgres answers, so wait for its health check instead of deploying straight away.
- First production deployment, then the two domain names and their records.
- 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.
| Connection | Host and port | Network | Meant for |
|---|---|---|---|
| Direct | db.<ref>.supabase.co, port 5432 | IPv6, or IPv4 with the paid add-on | Long-running servers, migrations, backups |
| Shared pooler, session mode | A pooler.supabase.com host, port 5432 | IPv4 on every plan | Long-running servers on IPv4-only networks |
| Shared pooler, transaction mode | The same pooler host, port 6543 | IPv4 on every plan | Serverless 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.
A example.com <IPv4 address Vercel shows for the project> DNS only
CNAME www.example.com <CNAME target Vercel shows for the project> DNS onlyVariables 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
- Project creation is refused with a message about Git. The Vercel GitHub app is missing on the account that owns the repository, or cannot see that repository.
- Supabase refuses the new project. The free plan allows two active projects. Pause or delete one, or upgrade the organisation.
- The site worked last month and now cannot reach its database. Supabase pauses free projects that had too little database activity over a week. Data and settings are kept, and paid plans are not paused.
- Vercel reports an invalid configuration for the domain. Its troubleshooting table points first at conflicting A, AAAA or CNAME records on the same host name. Shipyard stops on such a conflict and names the record.
- The domain is refused as already in use. It is attached to another Vercel project or account. Remove it there, or verify with the
_vercelTXT record. - You asked for a background worker. Vercel has none. Use Railway for hosting, or run scheduled jobs with Vercel Cron.
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 S111000000000000The 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.
- Vercel: A project connected to your repository, with variables, the bare domain and www.
- Supabase: A project in your region, with its connection string and keys written into your host.
- Cloudflare DNS: The zone, the nameservers and every record your host, email and Google need.
- GitHub: A private repository with the starter committed, connected to your host so every push deploys.
Sources
- Vercel: adding and configuring a custom domainvercel.com
- Vercel: environment variablesvercel.com
- Vercel: using Cloudflare and other reverse proxiesvercel.com
- Vercel: migrate to Vercel from Cloudflarevercel.com
- Vercel: terms of servicevercel.com
- Supabase: connect to your databasesupabase.com
- Supabase: API keyssupabase.com
- Supabase: do projects pause when inactive?supabase.com
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 stackRead next
- Vercel for a new SaaS
- Supabase for a new product
- Railway or Vercel for your first SaaS
- Why your app cannot send email after deploy
- Next.js on Railway with Postgres, Resend and Stripe: how the pieces connect
- Railway with Supabase as the database and Supabase Auth for sign-in
- Cloudflare Registrar or Namecheap for a new product's domain