Local Testing Fixes
This document explains what was fixed to enable local testing of the Supabase connection feature.
Issues Fixed
1. API Not Starting - Missing ENCRYPTION_KEY
Problem: API was crashing on startup because it couldn't find ENCRYPTION_KEY.
Fix:
- Updated dotenv configuration to load
.env.localfrom project root - Added better error handling for missing environment variables
Action Required:
- Ensure
.env.localexists in project root withENCRYPTION_KEYset - Generate key:
openssl rand -base64 32
2. Connections Form Not Working
Problem: The form had a TODO comment and wasn't actually making API calls.
Fix:
- Created API client utility (
apps/web/src/lib/api.ts) - Implemented full API integration in connections page
- Added form state management
- Added loading states and error handling
- Added session-token based auth handling
3. Missing Auth Context Propagation
Problem: API identity was previously passed as userId in request params/body.
Fix:
- Removed
userIdrequest contracts for protected routes - Enforced bearer-token auth on
/api/connections,/api/jobs, and/api/alerts - Updated frontend API client to use session-issued JWT access tokens
How to Test
Step 1: Verify Environment
-
Check
.env.localexists:cat .env.local | grep ENCRYPTION_KEY -
If missing or using placeholder, generate and set:
openssl rand -base64 32 # Copy output and add to .env.local
Step 2: Ensure Database is Set Up
-
Check database exists:
psql -l | grep unifiedcron -
Run migrations if needed:
cd packages/database pnpm build node dist/migrate.js
Step 3: Start Servers
-
Start development servers:
pnpm dev -
Verify both are running:
Step 4: Test Supabase Connection
-
Set up Supabase (if not done):
- Run SQL from
docs/supabase-setup.sqlin Supabase SQL Editor - Create the dedicated reader and obtain its session-pooler connection string
- Run SQL from
-
Test in UnifiedCron:
- Go to http://localhost:3000/connections (opens in a new tab)
- Click "Add Supabase Connection"
- Fill in:
- Label: "Test Connection"
- PostgreSQL connection string: Dedicated reader credentials
- CA certificate: Project certificate if required
- Click "Test & Connect"
-
What should happen:
- Form shows "Connecting..." while submitting
- Modal closes on success
- Connection appears in the list
- Error message shows if something fails
Step 5: Verify Connection Works
- Check connection appears in the connections list
- Test connection using the Test button
- Refresh jobs to discover cron jobs from Supabase
Debugging
If Form Still Doesn't Work
-
Check browser console:
- Open Developer Tools (F12)
- Look for JavaScript errors
- Check Network tab for failed requests
-
Check API is running:
curl http://localhost:3001/health -
Check API logs:
- Look at terminal where
pnpm devis running - Check for error messages
- Look at terminal where
-
Test API directly (authenticated endpoint):
curl http://localhost:3001/api/users/me \ -H "Authorization: Bearer <jwt-token>"
Common Error Messages
"Failed to connect to API"
- API is not running
- Check port 3001 is accessible
- Restart API server
"Authentication required"
- Session token is missing or expired
- Sign in again at
/auth/signin - Verify
JWT_SECRETis set in.env.local
"Failed to create connection"
- Check API logs for detailed error
- Verify Supabase credentials are correct
- Check database is accessible
Connection created but test fails
- Supabase views might not be set up
- Run SQL from
docs/supabase-setup.sql - Verify Project URL and Anon Key
Files Changed
apps/web/src/lib/api.ts- New API clientapps/web/src/app/connections/page.tsx- Full API integrationapps/api/src/routes/users.ts- Authenticated user profile endpointapps/api/src/index.ts- Better env loadingpackages/database/src/migrate.ts- Ordered migration framework with compatibility support
Next Steps
After successful connection:
- Test job discovery (Refresh Jobs)
- View jobs in dashboard
- Test connection refresh
- Try deleting and re-adding connections