Lovable Env Vars Vanish on Deploy? Fix the Vanishing Env-Var Before Your Login Breaks
If your Lovable app works in the editor but breaks once deployed — blank screen, a supabaseUrl is required error, or a login that redirects to localhost — your environment variables did not vanish. They were never set on the host. The editor injects its own values at preview time; your external host starts with an empty environment until you add them. The fix is in two places: the host's env panel and your Supabase Auth URL settings.
By Founder Name · Last verified: 2026-06-25
Why do my Lovable env variables disappear when I deploy?
They do not disappear — they were never present on the host. The Lovable editor injects VITE_SUPABASE_URL and your anon key into the preview sandbox automatically, so your app appears configured. When you deploy to an external host like Vercel or Netlify, that host starts with a completely empty environment. Vite bakes env vars in at build time, so a missing variable means the build ships with undefined where your Supabase URL should be.
This pattern is common enough that we have a name for it: The Vanishing Env-Var. The variable looks present everywhere you check inside Lovable, so the absence is invisible until the production build runs against a host that never received it. Because Vite resolves import.meta.env.VITE_SUPABASE_URL at build time and not at runtime, there is no way to patch it after the fact — the value is already compiled into your bundle as undefined.
The two values that vanish most often are VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY. When either is missing, the Supabase client cannot initialise and throws supabaseUrl is required, which usually surfaces as a blank white screen the instant a real user loads the deployed site.
Why does my login redirect to localhost after deploying?
Because your Supabase Auth Site URL is still set to http://localhost:3000 — the value Lovable used during local preview. Supabase builds the magic-link and OAuth redirect from the Site URL configured in your project's Auth settings, not from the domain the request came from. So after sign-in, Supabase sends the user back to localhost, which their browser cannot reach, and the session silently fails to establish.
This is the second half of The Vanishing Env-Var, and it is the one that confuses people most: the env vars can be perfectly set on the host, the app loads, but authentication still breaks because the redirect target lives in Supabase's dashboard, not in your code or your host panel. You have to fix both places.
If you see the login complete, the URL flash your real domain, then bounce to localhost or a blank page, the Site URL and Redirect URLs in Supabase Auth are the culprit. Add your production domain to both fields and the loop clears.
Related: fix a Lovable login loop or redirect bug · Supabase RLS and permission errors
Where exactly do I add the missing env vars on my host?
In your host's environment-variables panel, before you trigger the build that ships to production. Each host has its own location, but the rule is identical everywhere: add VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY with the exact values from your Lovable or Supabase project, then redeploy so the build picks them up. Editing env vars never updates an already-built deployment — you must trigger a fresh build.
- Copy the two values from Supabase: open your project, go to Project Settings, then API. Copy the Project URL (this is VITE_SUPABASE_URL) and the anon public key (this is VITE_SUPABASE_ANON_KEY).
- Open your host's env panel — Vercel: Project Settings, then Environment Variables. Netlify: Site configuration, then Environment variables. Cloudflare Pages: Settings, then Variables and Secrets.
- Add VITE_SUPABASE_URL and paste the Project URL. Add VITE_SUPABASE_ANON_KEY and paste the anon key. Use the exact VITE_ prefix — no spaces, no quotes around the value.
- Set the environment scope to Production (and Preview, if you use preview deploys) so the variables apply to the build that users actually hit.
- Trigger a fresh deploy. On Vercel, redeploy without the build cache; on Netlify, clear cache and deploy site. Env-var changes only take effect on the next build, never the current one.
How do I stop the login from redirecting to localhost?
Set your production domain as the Site URL and add it to the Redirect URLs allow-list in Supabase Auth. The Site URL is the default redirect target; the Redirect URLs list is the set of destinations Supabase will permit. Until your real domain appears in both, every sign-in falls back to localhost and the session never completes on the live site.
- Open your Supabase project, go to Authentication, then URL Configuration.
- Set Site URL to your production domain, for example https://yourapp.com — not localhost, and not the Lovable preview URL.
- Under Redirect URLs, add https://yourapp.com/** (the wildcard allows any sub-path callback). If you use a custom auth callback route, add that exact path too.
- If you still test locally, keep http://localhost:3000/** in the Redirect URLs list as well — both can coexist; only the Site URL is the single default.
- Save, then sign out fully and sign in again on the production site to confirm the redirect lands on your domain and the session persists.
How can I tell which environment variable is actually missing?
Open the deployed site, press F12 for DevTools, and read the Console tab. The error string names the failure precisely: supabaseUrl is required means VITE_SUPABASE_URL is undefined in the build; an Invalid API key error from Supabase means the anon key is wrong or missing; a redirect to localhost means the Auth Site URL is unfixed. Match the symptom to the table below before changing anything.
| Symptom on deployed site | Root cause | Where to fix it |
|---|---|---|
| Blank white screen, console: supabaseUrl is required | VITE_SUPABASE_URL undefined in production build | Host env panel — add VITE_SUPABASE_URL, redeploy |
| Console: Invalid API key / 401 from Supabase | VITE_SUPABASE_ANON_KEY missing or wrong value | Host env panel — paste correct anon public key, redeploy |
| Login completes then redirects to localhost | Supabase Auth Site URL still set to localhost | Supabase: Authentication, then URL Configuration |
| OAuth/magic-link returns redirect_uri error | Production domain not in Redirect URLs allow-list | Supabase: add https://yourdomain.com/** to Redirect URLs |
| Var set on host but still undefined in browser | Missing VITE_ prefix — Vite stripped it from the bundle | Rename to VITE_*, redeploy with cache cleared |
| Worked, then broke after I edited env vars | Change saved but no fresh build was triggered | Trigger a new deploy — env changes need a rebuild |
| Data reads/writes 403 after env vars fixed | Separate issue: Row Level Security policy, not env vars | See RLS permissions guide, not the env panel |
Why did it work before and break only after I changed hosts or redeployed?
Because the Lovable preview and your external host are two different environments that never shared state. As long as you stayed inside Lovable's hosting, the editor's injected env vars kept the app alive. The moment you connected a custom domain, exported to Vercel or Netlify, or migrated off Lovable, you moved to an environment that started empty. Nothing broke — the missing config simply became visible.
This is closely related to The Stale-Commit Deploy: a deploy that ships an older or differently-configured build than the one you tested. If you changed env vars and the site still shows the old error, your host likely served a cached build. Clearing the build cache and redeploying forces it to pick up the new environment.
If you are migrating off Lovable to your own host and want the env and auth config moved cleanly the first time, our team handles the full handoff so the deploy works on the first build instead of the fifth.
Related: common Lovable deployment errors and how to clear them · the Deployment cluster hub
How do I verify the fix before I call it done?
Run a short verification sequence on the deployed site, not the editor preview. The most common false-positive is a fix that looks right in Lovable but still breaks for real users, because the editor still has its injected vars. Test the live domain in a fresh browser session to confirm both the env vars and the auth redirect are genuinely resolved.
- Open the production domain in an incognito window so no cached session masks the problem.
- Open DevTools (F12), load the site, and confirm there are zero red console errors and no supabaseUrl is required message.
- Sign in with a real account and confirm the redirect lands on your domain — not localhost — and the session persists on refresh.
- Trigger one authenticated data read and one write, and confirm both succeed in the Supabase table editor.
- If anything still fails, check the host's deploy log to confirm the build that shipped is the one that included your env-var changes.
When should I stop and bring in an engineer to fix the deploy?
If you have added the env vars, fixed the Supabase Site URL, redeployed with the cache cleared, and the build still ships broken, the root cause is structural — a build-pipeline config, a wrong key environment, or a deploy serving a stale commit. At that point another redeploy will not help. A senior engineer can read the actual build log, confirm exactly which value the bundle compiled, and ship a working deploy without further guessing.
Signs it is time to escalate: the same error persists after three clean redeploys; env vars read correctly in the host panel but the bundle still has undefined; or you have a custom domain, edge functions, and Supabase auth all in play and cannot isolate which layer is failing. Getting a specialist in early is almost always cheaper than days of redeploy roulette.
Our Lovable app rescue service does emergency deploy fixes: we diagnose the exact missing or misconfigured value, restore a working production build, and leave you with a written record of every env var and auth URL so the next deploy is reproducible.
Related: Lovable App Rescue service · book an urgent deploy fix
Frequently asked questions
Why do my env variables work in the Lovable editor but not after I deploy?
My deployed Lovable app shows a blank screen and supabaseUrl is required — how do I fix it?
Why does my login redirect to localhost after I deploy?
Do I need the VITE_ prefix on my Lovable environment variables?
I changed my env vars but the site still shows the old error — why?
Which Supabase key do I put in VITE_SUPABASE_ANON_KEY — anon or service_role?
Where do I add environment variables on Vercel, Netlify, and Cloudflare?
My env vars are correct but data reads now return 403 — is that still an env-var problem?
Could the wrong anon key cause an Invalid API key error after deploy?
I have tried everything and the deploy still ships broken — can someone just fix it?
App down or leaking data? Get an expert on it within 24–48h.
Book a free 30-minute audit call. We'll diagnose what's wrong and tell you exactly what it costs to fix.