1.6 KiB
1.6 KiB
Quick Fix: Database Connection Error
Problem
You're seeing: Invalid API key error
Solution: Use Direct PostgreSQL Connection (2 minutes)
Step 1: Get Database Connection String
- Go to your Supabase Dashboard: https://app.supabase.com
- Select your project
- Go to Settings (gear icon) → Database
- Scroll to Connection String section
- Select URI tab
- Copy the connection string (it looks like this):
postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres
Step 2: Replace Password
Replace [YOUR-PASSWORD] with your actual database password:
- If you don't know it, click Reset database password in Supabase
- Or use the password you set when creating the project
Step 3: Add to .env File
Create or edit backend/.env file:
# Direct PostgreSQL Connection (RECOMMENDED)
DATABASE_URL=postgresql://postgres:your_actual_password@db.your-project-ref.supabase.co:5432/postgres
# Server Configuration
PORT=3010
NODE_ENV=development
# CORS Configuration
CORS_ORIGIN=http://localhost:5173
Example:
DATABASE_URL=postgresql://postgres:MySecurePassword123@db.abcdefghijklmnop.supabase.co:5432/postgres
Step 4: Restart Server
cd backend
npm run dev
You should now see:
✅ Database connection successful (PostgreSQL direct)
Why This Works
- Direct PostgreSQL connection bypasses Supabase API keys
- Faster for heavy SQL queries (which this system uses)
- More reliable for analytical queries
- No API key expiration issues
Still Having Issues?
See TROUBLESHOOTING.md for detailed troubleshooting steps.