API Connection Errors
Troubleshoot API connection errors, CORS issues, and authentication failures in Supamode.
API errors typically manifest as failed requests in the browser console, "Network Error" messages, or unexpected behavior in the UI. This guide covers the most common API-related issues.
"Network Error" or "Failed to Fetch"
Cause
The frontend cannot reach the API server.
Diagnosis
Open browser DevTools (F12) → Network tab. Look for failed requests to /api/* endpoints.
Fixes
1. Verify API is running
Check the API server is accessible:
curl http://localhost:3000/api/v1/health# Expected: {"status":"ok"}2. Check environment variables
In apps/app/.env, ensure VITE_SITE_URL is correct:
VITE_SITE_URL=http://localhost:51733. Verify proxy configuration
Vite proxies /api/* requests. If this isn't working, check apps/app/vite.config.ts has the proxy configured:
server: { proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } }}CORS Errors
Symptoms
Browser console shows: Access to fetch has been blocked by CORS policy
Cause
The API is rejecting requests from the frontend's origin.
Fixes
1. Set APP_URL correctly
In apps/api/.env:
APP_URL=http://localhost:5173This must match exactly where your frontend runs, including protocol and port.
2. Production domains
For production, use the full domain:
APP_URL=https://admin.yourdomain.com"Unauthorized" or 401 Errors
Symptoms
API requests return 401 status or "Unauthorized" messages.
Causes and Fixes
1. Session expired
Sign out and sign back in to refresh your JWT token.
2. Missing or invalid Supabase keys
Verify keys in apps/api/.env:
SUPABASE_URL=https://YOUR_PROJECT.supabase.coSUPABASE_ANON_KEY=your-anon-keySERVICE_ROLE_KEY=your-service-role-key3. User lacks Supamode account
A Supabase Auth user exists but doesn't have a corresponding Supamode account. Check Settings > Members to verify the user has an account with a role.
4. Check JWT in request
In DevTools → Network, click a failed request and check the Authorization header. It should contain a Bearer token.
"Invalid API Key" Errors
Cause
The Supabase anon key or service role key is incorrect.
Fixes
- Go to Supabase Dashboard → Settings → API
- Copy the correct keys
- Update
apps/api/.envandapps/app/.env - Restart both servers
Database Connection Errors
Symptoms
API logs show: Connection refused or ECONNREFUSED
Fixes
1. Check database URL
In apps/api/.env:
SUPABASE_DATABASE_URL=postgresql://postgres:PASSWORD@db.YOUR_PROJECT.supabase.co:5432/postgres2. For local development
SUPABASE_DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:54332/postgres3. Verify Supabase is running
For local development:
pnpm supabase:web:startCheck the database is accessible:
psql $SUPABASE_DATABASE_URL -c "SELECT 1"500 Internal Server Errors
Diagnosis
Check API server logs for the actual error. The logs will show the stack trace.
Common Causes
1. Missing environment variables
Ensure all required variables are set. The API logs which variables are missing on startup.
2. Database schema mismatch
If you see "relation does not exist" errors, run migrations:
pnpm supabase:web:reset3. Permission denied on RLS
Check the database user has necessary permissions and RLS policies are correct.
Timeout Errors
Symptoms
Requests hang and eventually fail with timeout errors.
Fixes
1. Check for slow queries
Enable performance logging in apps/api/.env:
PERF_LOG_LEVEL=basic2. Add database indexes
For frequently queried columns, add indexes in your Supabase migrations.
3. Reduce data volume
Use filters to limit the data returned. Add time-based filters for large tables.
Debugging Tips
Enable Verbose Logging
Set in apps/api/.env:
PERF_LOG_LEVEL=detailedCheck API Health
curl -v http://localhost:3000/api/v1/healthView Request/Response Details
In browser DevTools → Network:
- Click the failed request
- Check Headers tab for request details
- Check Response tab for error messages
- Check Timing tab for slow requests
Related Documentation
- Environment Variables - Complete reference for all configuration options
- Running Supamode - Local development setup
- Performance Issues - Optimizing slow queries and large datasets