- 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.
5.4 KiB
5.4 KiB
🚀 Quick Start - Test the Enhanced Logging
Time needed: 5 minutes
What you'll do: Add logging, rebuild, check console
Goal: Find the source of undefined hash error
Step 1: Verify Files Were Modified ✅
# Check if logging code is in place
grep -l "\[BlockchainVisualizer\]" /home/paul/CIA/e-voting-system/frontend/components/blockchain-visualizer.tsx
# Should output: /home/paul/CIA/e-voting-system/frontend/components/blockchain-visualizer.tsx
Expected: File found ✅
Step 2: Rebuild Frontend
cd /home/paul/CIA/e-voting-system
# Restart the frontend container
docker compose restart frontend
# Wait for it to be ready
sleep 5
echo "✅ Frontend restarted with new logging"
Expected: No errors, frontend running ✅
Step 3: Open Your Browser
- Open browser (Chrome, Firefox, Edge, etc.)
- Go to:
http://localhost:3000/dashboard/blockchain - Press F12 to open Developer Tools
- Click "Console" tab
Expected: Page loads, console is open ✅
Step 4: Select an Election
- Look for dropdown with election names
- Click on it (e.g., "Election Présidentielle 2025")
- Wait for blockchain to load (5-10 seconds)
- Watch the Console for logs
Expected: Logs appear in console ✅
Step 5: Look for Your Logs
Search in Console:
Press Ctrl+F and search for: [truncateHash]
You should see output like:
[BlockchainPage] Fetching blockchain for election: 1
[BlockchainPage] Fetch response status: 200
[BlockchainPage] Received blockchain data: { blocksCount: 5, ... }
[BlockchainVisualizer] Component mounted/updated { dataExists: true, ... }
[truncateHash] Called with: { hash: "genesis", type: "string", ... }
[truncateHash] Result: genesis
[truncateHash] Called with: { hash: "", type: "string", isEmpty: true, ... }
[truncateHash] Empty string received
[truncateHash] Result: N/A
Step 6: Check for the Problem
Look for any of these problematic entries:
[truncateHash] Called with: { hash: undefined, type: "undefined", isUndefined: true, ... }
[truncateHash] Received undefined
What this means:
- ✅ If NOT found: The fix is working! No undefined values
- ❌ If FOUND: Still getting undefined from somewhere
Step 7: Copy the Full Console Output
- Right-click in console
- Click "Save as..."
- Save to file like
console-output.txt
OR manually copy all logs:
- Select all in console with
Ctrl+A - Copy with
Ctrl+C - Paste into text editor
📊 What Each Log Tells You
| Log | Means |
|---|---|
[BlockchainPage] Fetching... |
Data is being fetched from backend ✅ |
Fetch response status: 200 |
Backend returned data successfully ✅ |
[BlockchainVisualizer] Component mounted |
React component is rendering ✅ |
First block structure: { transaction_id: "genesis"... } |
Data has values ✅ |
First block structure: { transaction_id: undefined... } |
❌ Data is corrupted! |
[truncateHash] Called with: { hash: "abc"... } |
Working on valid hash ✅ |
[truncateHash] Called with: { hash: undefined... } |
❌ Receiving undefined! |
[truncateHash] Result: N/A |
Handled empty/undefined gracefully ✅ |
🎯 Quick Checklist
- Frontend container restarted
- Opened http://localhost:3000/dashboard/blockchain
- Opened browser console (F12)
- Selected an election
- Saw logs in console
- Searched for
[truncateHash] - Found expected output
- No
undefinedvalues in truncateHash logs
🆘 Troubleshooting
I don't see any logs
Solution:
- Clear browser cache:
Ctrl+Shift+Del→ Select "Cached images" - Hard refresh:
Ctrl+Shift+R - Close and reopen console:
F12 - Check that frontend is running:
docker ps
I see old logs from before rebuild
Solution:
- Clear console: Type in console
console.clear() - Refresh page:
F5 - Select election again
Still seeing truncateHash errors
Solution:
- Copy the console output
- Look at the full logs
- Check what data is being received from backend
- Send the logs for analysis
📝 What to Report
If you see truncateHash errors, copy and share:
- The exact error message from console
- The data structure that was logged
- The
[BlockchainPage] Received blockchain datasection - Any
undefinedvalues you see
Example to share:
[BlockchainPage] Fetch response status: 200
[BlockchainPage] Received blockchain data: {
blocksCount: 5,
hasVerification: true,
firstBlockStructure: {
index: 0,
transaction_id: "genesis",
encrypted_vote: "",
signature: ""
}
}
[truncateHash] Called with: { hash: undefined, type: "undefined", isUndefined: true }
[truncateHash] Received undefined
✅ Success Criteria
✅ If you see:
[truncateHash] Result: N/A
[truncateHash] Result: abc123de...
No "undefined" entries
→ Logging is working ✅
❌ If you see:
[truncateHash] Received undefined
hash: undefined, type: "undefined"
→ Found the problem! ✅
🎯 Next Step
Once you've run through these steps:
- Share the console output if you see errors
- Confirm working if no errors
- We can debug from there if needed
Time: ~5 minutes
Complexity: Simple - just observe logs
Risk: None - read-only logging
Benefit: Complete visibility into the issue
Let's find out what's happening! 🔍