Vercel Environment Variables Not Working? 7 Supabase Fixes
Vercel environment variables work locally but fail after deployment? Fix Supabase keys, Preview scopes, redirect URLs, and redeployment issues.

Your app works locally.
Maybe the production site even works.
Then you open a Vercel Preview deployment and suddenly authentication fails, Supabase cannot initialise, or the application says an environment variable is missing.
I ran into exactly this kind of problem while building a real web application with Next.js, Supabase, GitHub, and Vercel.
My first instinct was to change the code.
That was often the wrong place to start.
The code could be correct while the deployment was running with a different set of environment variables, a different redirect URL, or an older build.
The question that helped me most was simple:
What is different about the environment where this fails?
This is the troubleshooting process I now use before I start rewriting working code.
Quick answer: check these 7 things first
If Vercel environment variables are not working with Supabase, check these in order:
- Make sure you are editing the correct Vercel project.
- Confirm the environment variable names exactly match the code.
- Check whether each variable is available in Preview, Production, or Development.
- Redeploy after changing environment variables.
- Confirm the Supabase project URL and publishable key belong to the correct project.
- Check Supabase Auth redirect URLs separately from environment variables.
- Test the exact new deployment that was failing.
For me, the most common problem was simpler than I expected:
Production had the variable. Preview did not.
1. Make sure you are editing the correct Vercel project
This sounds obvious, but it is one of the first things I check now.
When several GitHub repositories, v0 projects, custom domains, and Vercel deployments are involved, it is easy to open the wrong project and change the right variable in the wrong place.
Before changing anything, confirm:
- the Vercel project name
- the connected GitHub repository
- the production branch
- the custom domain
- the exact deployment URL that is failing
If those do not match the project you think you are debugging, stop there.
Environment variables added to another Vercel project will not help the deployment in front of you.
2. Match the environment variable names exactly
The variable name stored in Vercel and the variable name referenced by the application must match exactly.
For a current Supabase browser client, the public configuration may look like this:
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
And the client may read the same names:
import { createClient } from "@supabase/supabase-js"
export const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!
)
A small naming mismatch can create a surprisingly confusing error.
For example, this will not work:
- Vercel stores
NEXT_PUBLIC_SUPABASE_ANON_KEY - the application reads
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
Both values may be valid keys, but the code is asking for a variable name that does not exist.
Supabase's current key model uses a publishable key for public clients and a secret key for trusted server-side components. Existing projects may still use the legacy anon and service_role keys during migration.
The important rule is:
Use the key type your code expects, and make the variable name match exactly.
3. Understand Preview vs Production environment variables
This was the part I underestimated.
Vercel does not treat every deployment as the same environment.
| Vercel environment | Typical use | What can go wrong | | --- | --- | --- | | Production | Live production deployment | Works live, so you assume Preview must also work | | Preview | Pull requests and non-production branches | Required variables may not be available here | | Development | Local development | Local values may differ from cloud deployments |
A site can therefore behave like this:
- local development works
- Production works
- Preview fails
That does not automatically mean the code is inconsistent.
The environments may simply have different configuration.
In Vercel, review the scope assigned to each required variable. If the failing deployment is a Preview deployment, make sure the variables it needs are available to Preview.
For a small project using one Supabase project across environments, you may intentionally use the same public project URL and publishable key in more than one Vercel environment.
For a larger or more sensitive application, separate development or staging infrastructure is safer.
The important thing is not that every environment must be identical.
It is that you know which values each environment is supposed to use.
4. Redeploy after changing environment variables
This is one of the easiest steps to miss.
Changing an environment variable in Vercel does not rewrite an already-created deployment.
The updated value applies to a new deployment.
So after adding or changing an environment variable:
- save the change in Vercel
- create a new deployment or redeploy
- wait for the build to complete
- open the newly generated deployment
- test the real user flow again
Do not assume that refreshing an old Preview URL is testing the new configuration.
This matters especially with public Next.js environment variables because values exposed to browser code can be included during the build.
My rule is now simple:
Environment variable changed? Redeploy before debugging anything else.
Vercel's current environment variable documentation also notes that changes take effect on new deployments rather than altering previous deployments.
5. Check the Supabase URL and publishable key
A variable can exist and still contain the wrong value.
That is why I now ask two separate questions:
Does the variable exist?
and
Does the value belong to the correct Supabase project?
Check the Supabase project URL.
Check the publishable key.
Make sure they both come from the same project you intend this deployment to use.
For browser-side code, Supabase's current guidance is to use the publishable key. A secret key is for controlled backend components and must not be exposed in public client code.
That distinction matters.
A deployment working successfully is not enough.
It also needs to be configured safely.
Never put a secret key in a public environment variable
A variable beginning with NEXT_PUBLIC_ can be exposed to browser-side code.
Do not put a Supabase secret key or legacy service_role key there.
For public browser applications, use the publishable key and enforce real data access through authentication, database grants, and Row Level Security.
6. Check Supabase redirect URLs separately
Sometimes the environment variables are correct and login still fails.
At that point, the problem may not be the variables.
It may be Supabase Auth redirect configuration.
This is especially common when:
- OAuth works locally but fails on a Vercel Preview
- email confirmation returns to the wrong domain
- password reset opens the wrong URL
- Production authentication works but Preview authentication does not
A Production domain and a Vercel Preview domain are different URLs.
Supabase allows you to configure the main Site URL and additional redirect URLs. Its current documentation includes wildcard patterns for Vercel Preview URLs.
The practical lesson for me was this:
Environment variables and redirect URLs are connected parts of the same flow, but they are not the same setting.
Check them separately.
For production, use the real production site URL.
For Preview, allow only the Preview patterns you intentionally need.
Avoid making redirect rules broader than necessary.
7. Test the exact deployment that was failing
This sounds almost too simple to include.
It matters.
When several deployments exist at once, it is easy to make a fix and then keep testing an older URL.
Before deciding that the change did not work, check:
- the deployment creation time
- the commit it was built from
- whether the environment variable change happened before that deployment
- whether you are testing Preview or Production
- whether the domain points to the deployment you expect
The goal is to know exactly what you are testing.
A safe way to check whether variables exist
Do not print complete API keys into browser logs or build logs.
If you need temporary debugging, check only whether the variable is present:
const envStatus = {
hasSupabaseUrl: Boolean(process.env.NEXT_PUBLIC_SUPABASE_URL),
hasSupabasePublishableKey: Boolean(
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
),
}
console.log(envStatus)
Remove temporary debugging once the problem is solved.
Then test the real flow, not only the presence of variables:
- does the page load?
- can the user sign in?
- does the callback return to the correct site?
- can the user access only the data they should see?
- does the same flow behave correctly in Preview and Production?
A successful build does not prove authentication and permissions are correct.
My practical environment map
Writing down the intended configuration makes deployment problems much easier to reason about.
| Application stage | Vercel environment | Supabase target | Purpose | | --- | --- | --- | --- | | Local development | Development | local or development project | daily development | | Feature testing | Preview | staging or preview project | test before release | | Live application | Production | production project | real users and data |
Not every project needs three separate Supabase projects.
But every project benefits from knowing what each environment is connected to.
If Preview temporarily shares the Production database, document that clearly and test carefully.
v0-specific checks
If the project started in v0, also confirm:
- which GitHub repository the project is using
- which Vercel project is connected
- which branch produced the failing deployment
- whether Supabase is connected to the expected project
- whether the variable names match the generated code
- whether Preview has the variables it needs
- whether you created a new deployment after the change
Modern AI development tools can make integrations feel automatic.
That convenience is useful.
It does not remove the need to verify the actual project, branch, environment, and credentials.
Common fixes that waste time
Rewriting the Supabase client first
If the same code works locally or in Production, compare the environment before replacing the client setup.
Adding keys directly to source code
This may appear to solve the immediate problem, but it creates a security and maintenance problem. Keep credentials out of the repository.
Using a secret key in NEXT_PUBLIC_
Never expose a Supabase secret or legacy service_role key in browser code.
Testing an old deployment
Environment variable changes apply to new deployments. Confirm the deployment time before deciding the fix failed.
Assuming a branch named staging is automatically a separate environment
A Git branch can still be running as a Vercel Preview deployment unless you deliberately configure a different environment strategy.
The branch name itself does not create infrastructure isolation.
Final troubleshooting checklist
- [ ] I am editing the correct Vercel project.
- [ ] The connected GitHub repository is correct.
- [ ] The failing branch and deployment are identified.
- [ ] Environment variable names exactly match the code.
- [ ]
NEXT_PUBLIC_SUPABASE_URLexists where the client needs it. - [ ] The expected Supabase publishable key exists.
- [ ] Preview variables are available to Preview.
- [ ] Production variables are available to Production.
- [ ] No secret or
service_rolekey is exposed to browser code. - [ ] I created a new deployment after changing variables.
- [ ] I am testing the new deployment.
- [ ] Supabase Auth redirect URLs include the intended domains.
- [ ] Row Level Security protects application data.
FAQ
Why are my Vercel environment variables undefined?
The variable may be missing from the environment where the deployment is running, the name may not match the code, or you may be testing a deployment created before the variable was added.
Do I need to redeploy after changing environment variables in Vercel?
Yes. Create a new deployment after changing environment variables and test that new deployment.
Why does Vercel work in Production but not Preview?
Preview and Production can have different environment variable configuration. A variable that exists in Production may not be available to a Preview deployment.
Why does Supabase work locally but not on Vercel?
Possible causes include missing Vercel variables, incorrect Supabase project values, environment scope differences, an old deployment, or Supabase Auth redirect URL configuration.
Should I use the Supabase anon key or publishable key?
Supabase's current key model uses publishable keys for public clients and secret keys for controlled server-side components. Existing projects may still use legacy keys while migrating.
Can I put a Supabase secret key in NEXT_PUBLIC_?
No. Public Next.js environment variables can be exposed to browser code. Keep secret and privileged server-side keys out of them.
What I learned
The biggest lesson was not a complicated coding technique.
It was learning to ask a better first question:
Which environment is this deployment actually using?
That question can save hours of unnecessary changes.
For the wider workflow, read how I use Vercel for real website deployments and why I chose Supabase once a real project needed users, permissions, and data.
If the main confusion is environment scope, see Vercel Preview vs Production Environment Variables Explained. If authentication works locally but fails after deployment, use Supabase Login Works Locally but Not on Vercel? 8 Fixes.
My broader workflow is explained in My AI Website Stack in 2026. If you are preparing a site for release, the AI Website Launch Checklist covers the final mobile, SEO, trust, and technical checks.
Environment variables are configuration, but they are also part of application architecture and security.
Name them clearly.
Scope them intentionally.
Redeploy after changes.
Then test the real user flow in every environment that matters.
Practical AI. Real Experience. Built in Public.