Troubleshooting Guide
Common issues and solutions for SocleStack development and deployment.
Quick Diagnostics
# Check if database is running
docker-compose ps
# Check environment variables are loaded
npm run dev # Watch for Zod validation errors at startup
# Check database connection
npx prisma db pull # Should succeed without errors
# Regenerate Prisma client
npx prisma generateDatabase Issues
"Can't reach database server"
Symptoms: Error: Can't reach database server at localhost:5432
Solutions:
- Start PostgreSQL:
docker-compose up -d - Wait a few seconds for container to be ready
- Verify it's running:
docker-compose ps(should show "Up")
"Database does not exist"
Symptoms: error: database "soclestack" does not exist
Solutions:
# Create database and run migrations
npx prisma db push
# Or if using migrations
npx prisma migrate dev"Prisma Client not generated"
Symptoms: @prisma/client did not initialize yet or import errors
Solutions:
npx prisma generateSchema drift / migration issues
Symptoms: Drift detected: Your database schema is not in sync
Solutions:
# Development: Reset and resync
npx prisma db push --force-reset
# Production: Create migration
npx prisma migrate dev --name describe_changesEnvironment Variable Issues
"Missing required environment variable"
Symptoms: Zod validation error at startup listing missing variables
Solutions:
- Copy example file:
cp .env.example .env.local - Fill in required values (see
docs/ENVIRONMENT.md) - Required variables:
DATABASE_URL- PostgreSQL connection stringSESSION_SECRET- 32+ character random stringJWT_SECRET- 32+ character random string
Generate secure secrets
# Generate a secure random secret
openssl rand -base64 32"Invalid DATABASE_URL format"
Symptoms: Prisma connection errors
Solution: Use format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE
# Local Docker
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/soclestack"
# With connection pooling (Supabase, Neon)
DATABASE_URL="postgresql://user:pass@host:5432/db?pgbouncer=true"Authentication Issues
"Invalid CSRF token"
Symptoms: 403 errors on form submissions
Causes & Solutions:
- Cookies blocked: Ensure cookies are enabled, check SameSite settings
- Token expired: Refresh the page to get new token
- Cross-origin request: API must be same origin or configure CORS
"Session expired" immediately after login
Symptoms: User logged out right after logging in
Causes & Solutions:
- Clock skew: Ensure server and client clocks are synchronized
- Cookie not set: Check browser dev tools > Application > Cookies
- HTTPS mismatch: In production, ensure
NEXTAUTH_URLuses HTTPS
Login works but user shows as unauthenticated
Symptoms: Login succeeds but /api/auth/me returns 401
Solutions:
- Check cookies are being sent (credentials: 'include')
- Verify SESSION_SECRET hasn't changed between requests
- Check for proxy stripping cookies (X-Forwarded-* headers)
OAuth Issues
"OAuth callback error"
Symptoms: Redirect to error page after OAuth provider authorization
Causes & Solutions:
- Callback URL mismatch: Provider callback must exactly match:
- Google:
http://localhost:3000/api/auth/oauth/google/callback - GitHub:
http://localhost:3000/api/auth/oauth/github/callback
- Google:
- Missing credentials: Set
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET, etc. - State token expired: OAuth must complete within 10 minutes
"Account already linked"
Symptoms: Error when trying to link OAuth account
Solution: Each OAuth account can only link to one user. Check if already linked to another account.
OAuth works locally but not in production
Checklist:
- [ ] Update callback URLs in provider console to production domain
- [ ] Set
NEXTAUTH_URLto production URL - [ ] Ensure HTTPS is configured
- [ ] Update OAuth credentials for production
Two-Factor Authentication Issues
"Invalid 2FA code"
Symptoms: TOTP code rejected during login or setup
Causes & Solutions:
- Clock drift: TOTP is time-based. Sync device clock with internet time
- Code expired: Codes are valid for 30 seconds. Enter quickly
- Wrong account: Verify authenticator app has correct account
Lost access to authenticator app
Solutions:
- Use one of the 10 backup codes provided during setup
- Ask admin to reset 2FA:
POST /api/admin/users/[id]/reset-2fa - Each backup code works once only
QR code not scanning
Solutions:
- Try manual entry - use the text code shown below QR
- Increase screen brightness
- Try different authenticator app (Google Authenticator, Authy, 1Password)
Rate Limiting Issues
"Too many requests" (429)
Symptoms: API returns 429 status code
Solutions:
- Wait: Rate limits reset after the window (usually 1 minute)
- Check headers:
X-RateLimit-Resetshows when limit resets - Development: Reset limits via
POST /api/test/reset-rate-limits
Rate limits too aggressive
Configuration: Edit src/lib/rate-limiter/index.ts or set environment:
# Use Redis for distributed rate limiting
UPSTASH_REDIS_REST_URL="https://..."
UPSTASH_REDIS_REST_TOKEN="..."Email Issues
Emails not sending in development
Expected behavior: In development without RESEND_API_KEY, emails log to console instead of sending.
To test real emails:
- Sign up at resend.com
- Get API key and set
RESEND_API_KEY - Verify your sending domain
"Email delivery failed"
Check:
- Email logs:
GET /api/admin/emails(admin only) - Resend dashboard for delivery status
- Spam folders for test emails
Email verification link expired
Solution: Request new verification email:
- Click "Resend verification email" on login page
- Or call
POST /api/auth/resend-verification
Build & TypeScript Issues
"Type error" during build
Symptoms: npm run build fails with TypeScript errors
Solutions:
# Check types without building
npx tsc --noEmit
# Common fix: regenerate Prisma types
npx prisma generate"Module not found" errors
Solutions:
# Clear Next.js cache
rm -rf .next
# Reinstall dependencies
rm -rf node_modules && npm install
# Regenerate Prisma client
npx prisma generateESLint errors blocking commit
Solutions:
# Auto-fix what's possible
npm run lint -- --fix
# Check specific file
npx eslint src/path/to/file.tsDevelopment Server Issues
Port 3000 already in use
Solutions:
# Find process using port
lsof -i :3000
# Kill it
kill -9 <PID>
# Or use different port
PORT=3001 npm run devHot reload not working
Solutions:
- Check file isn't in
.gitignore(ignored files don't trigger reload) - Restart dev server:
Ctrl+Cthennpm run dev - Clear Next.js cache:
rm -rf .next
Production Deployment Issues
"NEXTAUTH_URL must be set"
Solution: Set to your production URL:
NEXTAUTH_URL="https://your-domain.com"Database connection timeouts
Solutions:
- Use connection pooling (PgBouncer, Supabase pooler)
- Add
?connection_limit=1to DATABASE_URL for serverless - Configure pool settings in Prisma schema
Static assets not loading
Check:
next.config.jsbasePath if using subpath- CDN configuration for
/_next/static/paths - CORS headers for cross-origin asset loading
Getting Help
If your issue isn't listed here:
- Search existing issues: GitHub Issues
- Check documentation: Full Docs
- Open new issue: Include error messages, steps to reproduce, and environment details
Useful debug information to include
# System info
node --version
npm --version
# Check dependencies
npm ls prisma
npm ls next
# Environment (don't share secrets!)
cat .env.local | grep -v SECRET | grep -v PASSWORD | grep -v KEY