2.9 KiB
Portal Authentication Troubleshooting Guide
Issue: 401 Errors - Missing Authentication Header
If you're getting 401 errors when the portal client calls the portal-server endpoints, follow this debugging checklist:
1. Verify API Key Configuration
Server Side (portal-server/.env file):
API_KEYS=dev_key_123,test_key_456
Client Side: The API key is now configured in Rust code at src/config.rs
. For development, it's hardcoded to dev_key_123
to match the server.
⚠️ Important: The client's API key must match one of the keys in the server's API_KEYS
list.
2. Check Browser Console Logs
When you make a request, you should see these debug logs in the browser console:
✅ Portal configuration initialized
🔧 Portal config loaded - API key: Present
🔑 Using API key: dev_key_123
🔧 Creating payment intent...
🔧 Setting up Stripe payment for resident registration
3. Common Issues and Solutions
Issue: API Key authentication still failing
Cause: Client API key doesn't match server configuration Solution:
- Check
src/config.rs
- the client usesdev_key_123
by default - Ensure portal-server/.env has
API_KEYS=dev_key_123,test_key_456
- Restart both client and server after changes
Issue: Headers show correct API key but server still returns 401
Cause: Server API key mismatch Solution:
- Check portal-server/.env file has matching key in
API_KEYS
- Restart portal-server after changing .env
Issue: CORS errors
Cause: Portal-server CORS configuration
Solution: Ensure portal-server allows requests from http://127.0.0.1:8080
4. Manual Testing
Test the API key directly with curl:
curl -X POST http://127.0.0.1:3001/api/resident/create-payment-intent \
-H "Content-Type: application/json" \
-H "x-api-key: dev_key_123" \
-d '{"type":"resident_registration","amount":5000}'
5. Network Tab Inspection
- Open browser Developer Tools (F12)
- Go to Network tab
- Make a request from the portal
- Click on the request in the Network tab
- Check the "Request Headers" section
- Verify
x-api-key
header is present with valuedev_key_123
6. Configuration Changes
To change the API key for production:
- Edit
src/config.rs
and update theget_api_key()
function - Rebuild the client:
trunk build --release
- Update server's
.env
file to include the new key inAPI_KEYS
Quick Start Commands
# 1. Start portal-server (in portal-server directory)
cd ../portal-server
cargo run
# 2. Start portal client (in portal directory)
cd ../portal
trunk serve --open
Getting Help
If the issue persists:
- Check all console logs in browser
- Verify network requests in Developer Tools
- Confirm both client and server .env files are correct
- Test with curl to isolate client vs server issues