freezone/portal/TROUBLESHOOTING.md
2025-06-30 17:01:40 +02:00

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:

  1. Check src/config.rs - the client uses dev_key_123 by default
  2. Ensure portal-server/.env has API_KEYS=dev_key_123,test_key_456
  3. Restart both client and server after changes

Issue: Headers show correct API key but server still returns 401

Cause: Server API key mismatch Solution:

  1. Check portal-server/.env file has matching key in API_KEYS
  2. 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

  1. Open browser Developer Tools (F12)
  2. Go to Network tab
  3. Make a request from the portal
  4. Click on the request in the Network tab
  5. Check the "Request Headers" section
  6. Verify x-api-key header is present with value dev_key_123

6. Configuration Changes

To change the API key for production:

  1. Edit src/config.rs and update the get_api_key() function
  2. Rebuild the client: trunk build --release
  3. Update server's .env file to include the new key in API_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:

  1. Check all console logs in browser
  2. Verify network requests in Developer Tools
  3. Confirm both client and server .env files are correct
  4. Test with curl to isolate client vs server issues