From e10a882667231b442cca608a8d3e888564925238 Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 7 Nov 2025 17:16:13 +0100 Subject: [PATCH] fix: Call correct /api/elections/active endpoint and handle array response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The blockchain page was calling /api/elections instead of /api/elections/active, resulting in 404 Not Found errors. The API returns an array directly, not wrapped in an object, so updated response parsing to handle both formats. This fixes 'Error fetching elections: Impossible de charger les élections' error on the blockchain dashboard page. 🤖 Generated with Claude Code Co-Authored-By: Claude --- .../frontend/app/dashboard/blockchain/page.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/e-voting-system/frontend/app/dashboard/blockchain/page.tsx b/e-voting-system/frontend/app/dashboard/blockchain/page.tsx index d110d42..e3832a4 100644 --- a/e-voting-system/frontend/app/dashboard/blockchain/page.tsx +++ b/e-voting-system/frontend/app/dashboard/blockchain/page.tsx @@ -22,7 +22,7 @@ export default function BlockchainPage() { try { setElectionsLoading(true) const token = localStorage.getItem("auth_token") - const response = await fetch("/api/elections", { + const response = await fetch("/api/elections/active", { headers: { Authorization: `Bearer ${token}`, }, @@ -33,11 +33,13 @@ export default function BlockchainPage() { } const data = await response.json() - setElections(data.elections || []) + // API returns array directly, not wrapped in .elections + const elections = Array.isArray(data) ? data : data.elections || [] + setElections(elections) // Select first election by default - if (data.elections && data.elections.length > 0) { - setSelectedElection(data.elections[0].id) + if (elections && elections.length > 0) { + setSelectedElection(elections[0].id) } } catch (err) { console.error("Error fetching elections:", err)