This guide helps you resolve common issues with the Expense Management Application.
Symptoms:
POST http://localhost:5000/api/auth/login 401 (Unauthorized)- Cannot login to the application
- API requests fail with 401 status
Root Causes & Solutions:
# Check if your Backend/.env file has the correct values:
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_ANON_KEY=your_actual_anon_key_here
SUPABASE_SERVICE_ROLE_KEY=your_actual_service_role_key_hereFix:
- Go to supabase.com
- Open your project dashboard
- Go to Settings > API
- Copy the Project URL and API keys
- Update your
Backend/.envfile
Fix:
cd Backend
npm run init-dbOr manually run the SQL:
- Go to your Supabase dashboard
- Open SQL Editor
- Copy content from
Backend/src/config/database.sql - Execute the SQL
The authentication might succeed in Supabase but fail in our application if the user profile doesn't exist.
Fix:
- Try creating a new account through the signup page
- Or manually check your Supabase dashboard > Authentication > Users
Symptoms:
Access to fetch at 'http://localhost:5000/api/...' from origin 'http://localhost:5173' has been blocked by CORS policy
Fix:
- Check that
FRONTEND_URLinBackend/.envmatches your frontend URL:FRONTEND_URL=http://localhost:5173
- Restart the backend server after changing environment variables
Symptoms:
Error: Missing Supabase environment variablesCannot find moduleerrors
Fixes:
# Install all dependencies
npm run install-all
# Or install individually
cd Backend && npm install
cd ../Frontend && npm install# Create environment files
cp Backend/.env.example Backend/.env
cp Frontend/.env.example Frontend/.envSymptoms:
Database error. Please ensure the database is properly initialized.- SQL errors in console
Fixes:
- Go to your Supabase dashboard
- Ensure project is active (not paused)
- Check if your IP is blocked
- Go to Settings > API in Supabase dashboard
- Copy the
service_rolekey (not theanonkey) - Update
SUPABASE_SERVICE_ROLE_KEYinBackend/.env
cd Backend
npm run init-dbSymptoms:
- TypeScript errors
- Module not found errors
Fixes:
cd Frontend
rm -rf node_modules package-lock.json
npm installMake sure all required files exist:
tsconfig.jsontsconfig.app.jsontsconfig.node.json
Symptoms:
Error: listen EADDRINUSE: address already in use :::5000Error: listen EADDRINUSE: address already in use :::5173
Fixes:
# Find process using port 5000
netstat -ano | findstr :5000
# Kill the process (replace PID with actual process ID)
taskkill /PID <PID> /FUpdate ports in environment files:
# Backend/.env
PORT=5001
# Frontend/.env
VITE_API_URL=http://localhost:5001/apicurl http://localhost:5000/healthExpected response:
{
"status": "ok",
"message": "Expense Management API is running",
"timestamp": "2024-01-01T00:00:00.000Z"
}cd Backend
node -e "console.log('SUPABASE_URL:', process.env.SUPABASE_URL)"cd Backend
node -e "
import { supabase } from './src/config/supabase.js';
supabase.from('companies').select('count').then(console.log);
"- Open browser developer tools (F12)
- Check Console tab for errors
- Check Network tab for failed requests
Look for error messages in the terminal where you started the backend server.
If you're still having issues:
- Check the setup guide in
README.md - Run the setup script:
npm run setup - Verify all prerequisites are met
- Check Supabase dashboard for any issues
- Review error messages carefully - they often contain the solution
- Supabase project is created and active
- Environment variables are correctly set
- Database schema is initialized
- All dependencies are installed
- Ports 5000 and 5173 are available
- Both servers are running
- CORS is properly configured
- Always restart servers after changing environment variables
- Check the Supabase dashboard for authentication and database issues
- Use browser dev tools to see detailed error messages
- Check both frontend and backend console logs for errors
- Ensure your internet connection is stable for Supabase requests
Still need help? The error messages usually contain valuable clues - read them carefully! π