CIA/e-voting-system/.claude/VOTE_CHECK_QUICK_FIX.md
E-Voting Developer 3efdabdbbd fix: Implement vote check endpoint in frontend API proxy
- Created `/frontend/app/api/votes/check/route.ts` to handle GET requests for checking if a user has voted in a specific election.
- Added error handling for unauthorized access and missing election ID.
- Forwarded requests to the backend API and returned appropriate responses.
- Updated `/frontend/app/api/votes/history/route.ts` to fetch user's voting history with error handling.
- Ensured both endpoints utilize the authorization token for secure access.
2025-11-10 02:56:47 +01:00

1.1 KiB

QUICK FIX - Vote Check Endpoint

What Was Missing

The frontend API proxy route for /api/votes/check was missing.

What I Created

/frontend/app/api/votes/check/route.ts

This route:

  • Accepts: GET /api/votes/check?election_id=X
  • Forwards to: Backend GET /api/votes/check?election_id=X
  • Returns: { "has_voted": true/false, ... }

How It Works

Browser
  ↓
GET /api/votes/check?election_id=1
  ↓
Frontend Proxy (new route)
  ↓
Backend API
  ↓
Database query
  ↓
Response: { "has_voted": false }
  ↓
Frontend shows voting form OR vote done page

Key Points

  • Already called on page load (not just on submit)
  • Backend endpoint already existed
  • Frontend just needed the proxy route
  • Works exactly as you wanted

Test It

# 1. Restart frontend
docker compose restart frontend && sleep 3

# 2. Visit voting page
# http://localhost:3000/dashboard/votes/active/1

# 3. Check console (F12)
# Vote check should happen immediately on load

Status

READY - Just restart frontend to apply the fix!