Web App Hosting
In short: import the Git repo into Vercel, and use two Supabase projects: one for production and one for previews. Add the Supabase URL and keys under Settings → Environment Variables, with the production project’s values scoped to Production and the preview project’s values scoped to Preview and Development. Push a branch to get a preview URL. Merge to main to deploy production. Add both kinds of URL to Supabase’s Redirect URLs so sign-in works everywhere.
Overview
What: this guide puts a web app on Vercel, connects it to Supabase for the database and sign-in, and sets up two kinds of deployment:
| Deployment | Made when | URL | Talks to |
|---|---|---|---|
| Preview | You push any branch other than main, or open a pull request |
https://<your-project>-<hash>-<your-team>.vercel.app (a new one each push), plus a stable one per branch |
The staging Supabase project |
| Production | You push or merge to main |
Your domain, e.g. https://<your-domain> |
The production Supabase project |
| Development | You run the app on your machine | http://localhost:3000 |
The staging project, or a local Supabase stack |
Vercel builds the app and serves it. Supabase holds the data, the sign-in users and the files. Vercel never stores your data, so the only link between the two is a handful of environment variables.
Why: previews let you and reviewers click through a change before it goes live. Pointing them at a separate Supabase project means a broken migration or a test sign-up never touches real users’ data.
Who it’s for: developers deploying their first app to Vercel, who already have (or are about to create) a Supabase project. If you haven’t made the Supabase project yet, do Org and Project Creation first.
Prerequisites
| What | Details |
|---|---|
| Vercel account | Sign up at vercel.com with GitHub, GitLab or Bitbucket. The Hobby plan is fine to try this. Use Pro for a team or anything commercial. |
| A Git repo | The app pushed to GitHub, GitLab or Bitbucket, with a main branch. |
| Two Supabase projects | One for production, one for staging and previews. Org and Project Creation covers creating them and finding the URL and keys. |
| Node.js 20 or newer | For the Vercel CLI and the Supabase CLI. Check with node --version. |
| Vercel CLI (optional) | npm install --global vercel, then vercel --version. Only needed for Steps 5 and 6. |
About the code: the examples assume Next.js, which Vercel detects with no settings. For Vite, rename NEXT_PUBLIC_ to VITE_, read them with import.meta.env.VITE_... instead of process.env, and Vercel’s build command is vite build with output folder dist. Vercel detects both.
Architecture
The browser loads the app from Vercel, then talks to Supabase directly with the publishable key. Server code on Vercel (API routes, server actions) talks to Supabase with the secret key. Each Vercel environment has its own copy of those values.
flowchart LR
classDef user fill:#CBD5E1,stroke:#475569,color:#060913
classDef app fill:#38BDF8,stroke:#0284C7,color:#000810
classDef cloud fill:#0B1121,stroke:#38BDF8,color:#E2E8F0
classDef data fill:#075985,stroke:#38BDF8,color:#F8FAFC
classDef secret fill:#F59E0B,stroke:#B45309,color:#1C1917
U([Visitor]):::user -->|opens the site| V[Vercel edge network]:::cloud
V -->|serves pages + runs| A[Your app]:::app
U -->|data calls, publishable key| SB[Supabase API + Auth]:::cloud
A -->|server calls, secret key| SB
SB -->|row rules on| DB[(Postgres)]:::data
K{{Vercel env variables}}:::secret -.->|injected at build and run| A
Figure 1: Vercel serves the app and runs its server code. Supabase holds the data. The environment variables are the only thing joining them.
Each environment is a separate pairing of a Vercel deployment and a Supabase project.
flowchart TB
classDef user fill:#CBD5E1,stroke:#475569,color:#060913
classDef app fill:#38BDF8,stroke:#0284C7,color:#000810
classDef cloud fill:#0B1121,stroke:#38BDF8,color:#E2E8F0
classDef data fill:#075985,stroke:#38BDF8,color:#F8FAFC
classDef secret fill:#F59E0B,stroke:#B45309,color:#1C1917
classDef zone fill:transparent,stroke:#94A3B8,stroke-dasharray:4 3
subgraph Repo["Git repo"]
direction LR
Main[main branch]:::app
Feat[feature branches]:::app
end
subgraph Vercel["Vercel project"]
direction LR
Prod[Production deployment]:::cloud
Prev[Preview deployments]:::cloud
EnvP{{Production env vars}}:::secret
EnvS{{Preview env vars}}:::secret
end
subgraph Supa["Supabase"]
direction LR
SP[(Production project)]:::data
SS[(Staging project)]:::data
end
Main -->|push or merge| Prod
Feat -->|push or pull request| Prev
EnvP -.->|scoped to Production| Prod
EnvS -.->|scoped to Preview| Prev
Prod -->|URL + keys| SP
Prev -->|URL + keys| SS
class Repo,Vercel,Supa zone
Figure 2: Branches decide the deployment, the deployment decides which variables it gets, and the variables decide which Supabase project it talks to.
The full pipeline, from a branch to production. Database migrations run from GitHub Actions, not from Vercel, so the schema is in place before the code that needs it.
%%{init: {"theme": "base", "themeVariables": {"actorBkg": "#0B1121", "actorBorder": "#38BDF8", "actorTextColor": "#E2E8F0", "actorLineColor": "#718096", "signalColor": "#718096", "signalTextColor": "#718096", "textColor": "#718096", "loopTextColor": "#718096", "labelBoxBkgColor": "#38BDF8", "labelBoxBorderColor": "#0284C7", "labelTextColor": "#000810", "sequenceNumberColor": "#FFFFFF", "noteBkgColor": "#F59E0B", "noteBorderColor": "#B45309", "noteTextColor": "#1C1917"}}}%%
sequenceDiagram
autonumber
box rgba(148,163,184,0.15) Person
participant D as You
end
box rgba(56,189,248,0.15) Your app
participant G as Git repo
participant CI as GitHub Actions
end
box rgba(148,163,184,0.06) Services you use
participant V as Vercel
participant SS as Supabase staging
participant SP as Supabase production
end
D->>G: Push feature branch, open pull request
G->>CI: Pull request opened
CI->>SS: supabase db push --remote
G->>V: Webhook: new commit
V->>V: Build with Preview env vars
V-->>G: Preview URL on the pull request
D->>V: Clicks through the preview
V->>SS: Data and sign-in calls
D->>G: Merge to main
G->>CI: Push to main
CI->>SP: supabase db push --remote
G->>V: Webhook: new commit on main
V->>V: Build with Production env vars
V-->>D: Live on your domain
Figure 3: Previews build against staging, merges build against production. Migrations go first in each case.
Vercel and GitHub Actions start at the same moment, so a build can finish before a migration does. For a change that needs a new column, merge the migration in its own pull request first, then the code that uses it. That way the old code keeps working on the new schema.
Step 1: Import the repo into Vercel
- Open vercel.com/new and sign in.
- Under Import Git Repository, choose Install next to your Git provider if it isn’t connected, and allow access to the one repo you need (not every repo).
- Choose Import next to the repo.
- Check Framework Preset. It should say Next.js (or Vite). Leave Build Command and Output Directory as detected.
- If the app is in a subfolder of the repo, set Root Directory to that folder.
- Don’t add environment variables here yet. Choose Deploy.
The first build may fail or show errors where it calls Supabase. That’s expected: the variables come in Step 3.
You should now see the project dashboard, with a production URL like https://<your-project>.vercel.app.
Step 2: Set the production branch
- Open the project, then Settings → Environments → Production.
- Check Branch Tracking says
main. Change it if your production branch has another name.
Every other branch now gets preview deployments. To stop previews for some branches, use Settings → Git → Ignored Build Step.
Step 3: Add the environment variables
You need the same four names in every environment, with different values. Copy the values from each Supabase project’s Connect dialog (Org and Project Creation, Step 3).
| Name | What it is | Secret? | Production value | Preview and Development value |
|---|---|---|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Project URL, for the browser | No | https://<your-prod-ref>.supabase.co |
https://<your-staging-ref>.supabase.co |
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY |
sb_publishable_... key, for the browser |
No | Production publishable key | Staging publishable key |
SUPABASE_URL |
Project URL, for server code | No | Same as above | Same as above |
SUPABASE_SECRET_KEY |
sb_secret_... key, server only |
Yes | Production secret key | Staging secret key |
NEXT_PUBLIC_SITE_URL |
Where sign-in emails and redirects send people | No | https://<your-domain> |
Leave unset (see the code below) |
- Open Settings → Environment Variables.
- Type
NEXT_PUBLIC_SUPABASE_URLin Key and the production project URL in Value. - Under Environments, tick only Production.
- Choose Save.
- Add the same key again with the staging URL, and tick Preview and Development.
- Repeat for each row in the table.
- For
SUPABASE_SECRET_KEY, turn on Sensitive before you save. Vercel then never shows the value again, even to you.
Vercel also sets some variables for you on every deployment. Two are useful here:
| Name | Value |
|---|---|
VERCEL_ENV |
production, preview or development |
VERCEL_URL |
This deployment’s own host, without https:// |
Use them to work out the site URL, so sign-in links in a preview send people back to that preview and not to production:
export function getSiteUrl() { // NEXT_PUBLIC_ copies are inlined into the browser bundle at build time const url = process.env.NEXT_PUBLIC_SITE_URL ?? (process.env.NEXT_PUBLIC_VERCEL_URL && `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`) ?? 'http://localhost:3000' return url.endsWith('/') ? url : `${url}/`}NEXT_PUBLIC_VERCEL_URL is Vercel’s browser copy of VERCEL_URL, added automatically for Next.js. For Vite, add it yourself as VITE_VERCEL_URL, or call window.location.origin in the browser.
Variables are read when the app is built. Anything with NEXT_PUBLIC_ or VITE_ is baked into the JavaScript files. Changing a value does nothing until you redeploy: open Deployments, choose ⋯ on the latest one, then Redeploy.
Preview values can also be set for one branch only.
To test one branch against a different Supabase project, add a variable scoped to Preview and pick that branch under Preview → Select a custom Git branch. A branch-specific value wins over the general Preview value.
Step 4: Allow Vercel URLs in Supabase Auth
Supabase only sends people back to URLs on its allow list after sign-in, email confirmation or a password reset. Do this in both projects.
In the production project:
- Open Authentication → URL Configuration.
- Set Site URL to
https://<your-domain>. - Under Redirect URLs, add
https://<your-domain>/**.
In the staging project:
- Open Authentication → URL Configuration.
- Set Site URL to
http://localhost:3000. - Under Redirect URLs, add:
http://localhost:3000/**https://*-<your-team-slug>.vercel.app/**
Your team slug is in the preview URL after the last hyphen-separated hash, and under Team Settings → General.
Pass the redirect from getSiteUrl() when you start sign-in:
await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: `${getSiteUrl()}auth/callback` },})Security: never put the *.vercel.app wildcard in the production project. Anyone can deploy to vercel.app, and a broad wildcard would let their site receive your users’ sign-in codes. The pattern above is limited to your team’s slug, and it belongs only in staging.
If you use Google or Microsoft sign-in, their callback URL is Supabase’s, not Vercel’s, so nothing changes there. Sign In / Providers covers them.
Step 5: Work locally with the same variables
-
From the app folder, link it to the Vercel project. Choose the team and project when asked:
Terminal window vercel link -
Download the Development variables into a git-ignored file:
Terminal window vercel env pull .env.local -
Make sure git ignores it (once per repo):
Terminal window printf '%s\n' '.env*.local' '.vercel' >> .gitignore -
Start the app with
npm run dev. It talks to the staging Supabase project.
Values marked Sensitive aren’t downloaded. Get the staging secret key from your password manager (Configure for Code) and add it to .env.local yourself.
Step 6: Run database migrations from CI
Vercel builds code. It doesn’t change your database. Run migrations from GitHub Actions so staging gets them on every pull request and production gets them on merge. This uses the CLI setup from Org and Project Creation, Step 4.
-
In GitHub, open the repo, then Settings → Secrets and variables → Actions.
-
Add these repository secrets:
Secret Where it comes from SUPABASE_ACCESS_TOKENSupabase account menu → Access Tokens → Generate new token STAGING_PROJECT_REFThe staging project ref STAGING_DB_PASSWORDThe staging database password PRODUCTION_PROJECT_REFThe production project ref PRODUCTION_DB_PASSWORDThe production database password -
Save this as
.github/workflows/migrations.yml:name: Database migrationson:pull_request:paths: ['supabase/migrations/**']push:branches: [main]paths: ['supabase/migrations/**']jobs:migrate:runs-on: ubuntu-latest# Production pushes wait for approval if the environment has reviewersenvironment: ${{ github.event_name == 'push' && 'production' || 'staging' }}env:SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}SUPABASE_DB_PASSWORD: ${{ github.event_name == 'push' && secrets.PRODUCTION_DB_PASSWORD || secrets.STAGING_DB_PASSWORD }}PROJECT_REF: ${{ github.event_name == 'push' && secrets.PRODUCTION_PROJECT_REF || secrets.STAGING_PROJECT_REF }}steps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: 22- run: npm ci- run: npx supabase link --project-ref "$PROJECT_REF"- run: npx supabase db push --remote --yes -
Commit and push it on a branch, then open a pull request that adds a migration. The Database migrations check should pass, and the staging project should have the change.
Every open pull request pushes to the same staging database. Two pull requests with clashing migrations will fight. Keep migrations small and merge them quickly. If that gets painful, look at Supabase Branching, which gives each pull request its own short-lived database.
Step 7: Add your domain
- Open Settings → Domains and choose Add Domain.
- Type
<your-domain>and pick Production as the environment. - Add the DNS record Vercel shows (an
Arecord for the bare domain, or aCNAMEforwww) at your DNS provider. - Wait for the domain to show Valid Configuration. Vercel issues the HTTPS certificate for you.
- Update Site URL and Redirect URLs in the production Supabase project (Step 4) if the domain changed.
Security
Security: SUPABASE_SECRET_KEY skips row level security. Mark it Sensitive in Vercel, never give it a NEXT_PUBLIC_ or VITE_ prefix, and only read it in server code. If it ends up in the browser bundle, anyone can read and write every row.
- Separate projects: previews are less locked down than production (anyone on the team can deploy one, and the code is unreviewed). Keeping them on a staging Supabase project means a bad preview can’t touch real data. Don’t copy production data into staging without removing personal details first.
- Scope every variable: production values ticked for Production only. Check the Environments column on the variables page after each change.
- Protect previews: open Settings → Deployment Protection and keep Vercel Authentication on for Standard Protection. Only signed-in team members can then open preview URLs. Share one with a client through Share on the deployment, which makes a time-limited link.
- Pull requests from forks: on a public repo, leave Settings → Git → Fork Protection on, so a stranger’s pull request can’t build with your preview secrets.
- Git access: give the Vercel GitHub app access to only the repos it deploys.
- CI secrets: the Supabase access token can change every project on the account. Store it only as a GitHub secret, and add required reviewers to the
productionenvironment (Settings → Environments → production) so production migrations need an approval. - Rotate: if a key leaks, create a new one in Supabase (Project Settings → API Keys), update it in Vercel, redeploy, then revoke the old one. In that order, the site never runs without a working key.
- Row level security: the publishable key is public on purpose. Your tables are only safe if row level security is on for each one. Org and Project Creation, Security has the checklist.
Verify it works
- Push a branch with a small visible change and open a pull request.
- Within a few minutes, the Vercel bot comments on the pull request with a Preview link. Open it.
- Sign up with a test email. The user should appear in the staging project under Authentication → Users, and not in production.
- Open the browser developer tools, Sources tab, and search the JavaScript for
sb_secret_. There should be no matches. - Merge the pull request. Under Deployments, a new deployment with the Production label should appear, and your domain should show the change.
- On the production site, sign in with a real account. You should land back on
https://<your-domain>, not on avercel.appaddress orlocalhost.
Troubleshooting
| Problem or error | Likely cause | Fix |
|---|---|---|
supabaseUrl is required in the build log or browser |
The variable isn’t set for this environment, or the build ran before you added it. | Check the Environments column on the variables page, then Redeploy. |
| Changed a variable and nothing happened | Variables are read at build time. | Deployments → ⋯ → Redeploy. |
| Preview data shows up in production (or the reverse) | A variable is ticked for the wrong environment. | Fix the ticks so each value has only its own environment, then redeploy both. |
After sign-in you land on localhost:3000 |
The redirect URL isn’t on the allow list, so Supabase falls back to Site URL. | Add the preview or domain pattern under Authentication → URL Configuration (Step 4). |
Invalid Redirect URL or redirect_to is not allowed |
Same as above. | Same as above. Check the team slug in the wildcard matches the preview URL. |
| Preview asks you to sign in to Vercel | Deployment Protection is on. That’s intended. | Sign in with your Vercel account, or use Share for someone outside the team. |
relation "public.<table>" does not exist on a preview |
The migration hasn’t run on staging yet, or failed. | Check the Database migrations run on the pull request and re-run it. |
vercel env pull writes an empty secret key |
The variable is Sensitive, which can’t be downloaded. | Add it to .env.local by hand from your password manager. |
| Build works locally, fails on Vercel | Different Node version, or a file ignored by git. | Set Settings → Build and Deployment → Node.js Version to match node --version, and check the file is committed. |
Cleanup or rollback
- Roll back production: open Deployments, find the last good production deployment, choose ⋯ → Instant Rollback. It takes seconds and doesn’t rebuild. Roll forward by merging a fix; auto-promotion of new builds stays paused until you choose Undo Rollback or promote one yourself.
- Database rollbacks are separate: Vercel’s rollback doesn’t undo migrations. Write a new migration that reverses the change and push it (Org and Project Creation, Cleanup).
- Remove a preview: previews stop being built when the branch is deleted. Old ones can be deleted under Deployments.
- Remove everything: delete the Vercel project under Settings → General → Delete Project, remove the DNS records for your domain, delete
.github/workflows/migrations.ymland the GitHub secrets, and remove the Vercel URLs from both Supabase projects’ Redirect URLs.
Dependencies
Other dev-docs guides:
- Org and Project Creation — creating the Supabase projects, the keys, and migrations with the CLI
- Sign In / Providers — email, Google and Microsoft sign-in
- Configure for Code — keeping the secret keys and database passwords in 1Password
External services:
- Vercel — builds, hosts and serves the app, and stores its environment variables
- Supabase — database, sign-in and storage
- GitHub Actions — runs the database migrations
Versions
| Tool | Version | Notes |
|---|---|---|
| Vercel CLI | Latest | Only for vercel link and vercel env pull. Update with npm install --global vercel@latest. |
| Supabase CLI | 3.x | db push --remote --yes needs v3. Installed per repo as a dev dependency. |
| Node.js | 20 or newer | 22 used in the workflow. Match it in Vercel’s Node.js Version setting. |
@supabase/supabase-js |
2.x |
References
- Vercel environments — Production, Preview and Development
- Environment variables — scoping, branch-specific values and Sensitive variables
- System environment variables —
VERCEL_ENVandVERCEL_URL - Deployment Protection — Vercel Authentication and shareable links
- Instant Rollback
- Supabase redirect URLs — wildcards and Vercel preview URLs
- Supabase Branching — a database per pull request
- Managing environments with the Supabase CLI — the GitHub Actions pattern