This document describes the changes made to migrate the frontend from Supabase authentication to work with the new Python FastAPI backend that operates in development mode without authentication.
Problem: Frontend expected JWT authentication but backend operates without auth in development mode.
Solution:
- Updated
useEditorhook to checkVITE_DISABLE_AUTHenvironment variable - Modified API calls to work with or without authentication tokens
- Maintained backward compatibility for when authentication is enabled
Files Changed:
apps/frontend/src/hooks/useEditor.tsapps/frontend/src/services/api.ts
Problem: Frontend expected different field names and structure than the FastAPI backend provides.
Solution:
- Updated shared types to match the actual API structure
- Added conversion functions between API format and frontend format
- Maintained backward compatibility with optional legacy fields
API Structure Changes:
- Primary key:
vnum(integer) instead ofid(UUID) - Field names:
region_typeinstead oftype - Props:
region_props(number) instead ofprops(JSON string) - Additional fields:
region_reset_data,region_reset_time,region_type_name,sector_type_name
- Primary key:
vnum(integer) instead ofid(UUID) - Field names:
path_typeinstead oftype - Props:
path_props(number) instead ofprops(JSON string) - Additional fields:
path_type_name
- Simplified structure (no vnum yet in API)
- Direct coordinate instead of nested structure
Files Changed:
packages/shared/src/types/index.tsapps/frontend/src/services/api.ts
Problem: Backend wraps collection responses in {data: [...]} but single items are direct objects.
Solution:
- Updated API client to handle both response formats
- Added proper error handling for FastAPI error format
- Improved error messages and debugging
Files Changed:
apps/frontend/src/services/api.ts
Added helper functions to convert between API format and frontend format:
// Convert API regions to frontend format (adds compatibility fields)
const apiRegionToFrontend = (apiRegion: any): Region => ({ ... })
// Convert frontend regions to API format (removes frontend-only fields)
const frontendRegionToApi = (region: Omit<Region, 'id'>): any => ({ ... })The frontend now respects the VITE_DISABLE_AUTH=true setting to bypass authentication entirely:
# apps/frontend/.env
VITE_API_URL=http://localhost:8000/api
VITE_DISABLE_AUTH=trueThe frontend now correctly calls these FastAPI endpoints:
GET /api/health- Health checkGET /api/regions- List all regionsGET /api/regions/{vnum}- Get specific regionPOST /api/regions- Create new regionPUT /api/regions/{vnum}- Update regionDELETE /api/regions/{vnum}- Delete regionGET /api/paths- List all pathsGET /api/paths/{vnum}- Get specific pathPOST /api/paths- Create new pathPUT /api/paths/{vnum}- Update pathDELETE /api/paths/{vnum}- Delete path
Collections: Wrapped in {data: [...]}
{
"data": [
{
"vnum": 101,
"name": "Darkwood Forest",
"region_type": 1,
"coordinates": [...]
}
]
}Single Items: Direct objects
{
"vnum": 101,
"name": "Darkwood Forest",
"region_type": 1,
"coordinates": [...]
}After these changes, the frontend should:
- ✅ Load without authentication errors
- ✅ Connect to the FastAPI backend at
http://localhost:8000/api - ✅ Fetch and display existing regions and paths
- ✅ Allow creating new regions and paths
- ✅ Allow editing existing items
- ✅ Handle API errors gracefully
- Test with Real Data: Verify the frontend works with actual MUD database content
- Error Handling: Improve error messages and user feedback
- Authentication: When ready for production, implement API key authentication
- Points API: Complete the Points endpoints in the backend
- Type Safety: Consider using generated types from OpenAPI schema
- CORS Errors: Ensure backend allows
http://localhost:5173in CORS settings - API Connection: Verify backend is running on port 8000
- Data Format: Check browser network tab for API response format mismatches
- Authentication: Ensure
VITE_DISABLE_AUTH=trueis set correctly
Enable debug logging:
VITE_ENABLE_DEBUG=trueThis will show detailed API calls and responses in the browser console.