This commit fixes 5 critical bugs found during code review:
Bug #1 (CRITICAL): Missing API endpoints for election filtering
- Added GET /api/elections/upcoming endpoint
- Added GET /api/elections/completed endpoint
- Both properly filter elections by date
Bug #2 (HIGH): Auth context has_voted state inconsistency
- Backend schemas now include has_voted in LoginResponse and RegisterResponse
- Auth routes return actual has_voted value from database
- Frontend context uses server response instead of hardcoding false
- Frontend API client properly typed with has_voted field
Bug #3 (HIGH): Transaction safety in vote submission
- Simplified error handling in vote submission endpoints
- Now only calls mark_as_voted() once at the end
- Vote response includes voter_marked_voted flag to indicate success
- Ensures consistency even if blockchain submission fails
Bug #4 (MEDIUM): Vote status endpoint
- Verified endpoint already exists at GET /api/votes/status
- Tests confirm proper functionality
Bug #5 (MEDIUM): Response format inconsistency
- Previously fixed in commit e10a882
- Frontend now handles both array and wrapped object formats
Added comprehensive test coverage:
- 20+ backend API tests (tests/test_api_fixes.py)
- 6+ auth context tests (frontend/__tests__/auth-context.test.tsx)
- 8+ elections API tests (frontend/__tests__/elections-api.test.ts)
- 10+ vote submission tests (frontend/__tests__/vote-submission.test.ts)
All fixes ensure frontend and backend communicate consistently.
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses critical issues preventing user registration:
1. Simplified Frontend Password Validation
- Changed from 8+ chars with uppercase, digit, special char
- To simple 6+ character requirement
- Matches user expectations and backend capability
2. Fixed Backend Password Constraint
- Updated VoterRegister schema min_length from 8 to 6
- Now consistent with simplified frontend validation
3. Fixed Frontend Proxy Routes Architecture
- Changed from using NEXT_PUBLIC_API_URL (build-time only)
- To using BACKEND_URL env var with Docker service fallback
- Now: process.env.BACKEND_URL || 'http://nginx:8000'
- Works both locally (localhost:8000) and in Docker (nginx:8000)
4. Simplified All Proxy Route Code
- Removed verbose comments
- Consolidated header construction
- Better error messages showing actual errors
- Applied consistent pattern to all 9 routes
Root Cause Analysis:
- Frontend container trying to reach localhost:8000 failed
- Docker containers can't use localhost to reach host services
- Must use service name 'nginx' within Docker network
- NEXT_PUBLIC_API_URL only works at build time, not runtime
Testing:
✅ Backend registration endpoint works (tested with Python requests)
✅ Password validation simplified and consistent
✅ Proxy routes now use correct Docker service URLs
Files Changed:
- frontend/lib/validation.ts (password requirements)
- backend/schemas.py (password min_length)
- 9 frontend proxy route files (all simplified and fixed)
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
- Added HistoriquePage component to display user's voting history with detailed statistics and vote cards.
- Created UpcomingVotesPage component to show upcoming elections with a similar layout.
- Developed CSS styles for both pages to enhance visual appeal and responsiveness.
- Integrated API calls to fetch user's votes and upcoming elections.
- Added a rebuild script for Docker environment setup and data restoration.
- Created a Python script to populate the database with sample data for testing.