name: lovable-vps-supabase-env-vars
description: Fix HTTP 500 on Lovable/TanStack Start VPS apps caused by wrong Supabase credentials in systemd service
category: devops
Lovable/TanStack Start VPS Deployment — Supabase Env Vars Issue
Symptom
App returns {"status":500,"unhandled":true,"message":"HTTPError"} on ALL routes after deploying. curl shows HTTP 500. The app appears completely broken.
Root Cause
When Lovable apps are deployed to VPS, the systemd service file (/etc/systemd/system/) has hardcoded Environment= values for Supabase. These may be:
- - Wrong project credentials (pointing to a different Supabase project than the app actually uses)
- - Stale values from an old deployment
- - Missing entirely
- -
VITE_SUPABASE_URL(should match the project's Supabase URL) - -
VITE_SUPABASE_PROJECT_ID(should match the project ref) - -
VITE_SUPABASE_PUBLISHABLE_KEY(should match the anon key) - - DocCorretor (Documents):
nzaxsorgsecnmqwufawn→https://nzaxsorgsecnmqwufawn.supabase.co - - ComercialRS:
dauftiqcvgaydddoxqhh→https://dauftiqcvgaydddoxqhh.supabase.co
The app's .env file may be correct, but the systemd service overrides it with wrong values at runtime.
How to Diagnose
`bash
1. Check the .env file (correct values should be here)
cat /var/www/
2. Check the systemd service (THIS is what matters at runtime)
cat /etc/systemd/system/
`
Look for mismatches in:
Project References
How to Fix
Edit the systemd service:
`bash
sudo nano /etc/systemd/system/
`
Update the Environment= lines to match the correct values from .env:
`ini
Environment="SUPABASE_URL=https://nzaxsorgsecnmqwufawn.supabase.co"
Environment="VITE_SUPABASE_PROJECT_ID=nzaxsorgsecnmqwufawn"
Environment="VITE_SUPABASE_PUBLISHABLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
Environment="VITE_SUPABASE_URL=https://nzaxsorgsecnmqwufawn.supabase.co"
`
Then reload and restart:
`bash
sudo systemctl daemon-reload
sudo systemctl restart
`
Prevention
After any Lovable redeploy that touches environment variables, always check if the systemd service env vars still match the .env file — Lovable's deploy process may not update the service file automatically.