3.1 KiB
3.1 KiB
User Endpoint Refactoring - Changes Summary
Overview
This refactoring removes the redundant /auth/me endpoint and consolidates user profile retrieval through the proper /users/{user_id} endpoint, improving API consistency and reducing code duplication.
Problem Analysis
The system had two endpoints returning similar user information:
/auth/me- Returned current user from JWT token/users/{user_id}- Returned user by ID
This created redundancy and confusion in the API structure.
Changes Made
1. Backend Changes
File: services/auth/app/api/auth_operations.py
- Removed:
/auth/meendpoint (lines with@router.get("/me")) - Impact: The endpoint no longer exists in the auth service
- Reason: Redundant with
/users/{user_id}endpoint
2. Frontend Changes
File: frontend/src/api/services/user.ts
- Updated:
getCurrentUser()method - Before: Called
/users/me - After: Gets current user ID from auth store and calls
/users/{user_id} - Implementation:
async getCurrentUser(): Promise<UserResponse> { // Get current user ID from auth store const authStore = useAuthStore.getState(); const userId = authStore.user?.id; if (!userId) { throw new Error('No authenticated user found'); } return apiClient.get<UserResponse>(`${this.baseUrl}/${userId}`); }
3. API Client Changes
File: frontend/src/api/client/apiClient.ts
- Updated: Removed
/auth/mefromnoTenantEndpointsarray - Before:
/auth/mewas listed as a user-level endpoint - After: Removed since the endpoint no longer exists
- Note:
/auth/me/onboardingremains as it's a different endpoint
API Gateway Behavior
The gateway routing remains unchanged and works correctly:
- Frontend calls
/users/{user_id} - Gateway forwards to
/api/v1/auth/users/{user_id}in auth service - Auth service returns user data via
get_user_by_id()endpoint
Benefits
- Consistency: Single source of truth for user data
- Simplicity: Removes redundant endpoint
- Maintainability: Clearer API structure
- Performance: No duplicate data fetching logic
Testing
- Created verification script to ensure all changes are syntactically correct
- Verified that
/auth/meendpoint has been removed - Confirmed that UserService correctly uses user ID from auth store
- Validated that API client no longer references the removed endpoint
Migration Notes
- Breaking Change: Any direct calls to
/auth/mewill now return 404 - Replacement: Use
/users/{user_id}with the current user's ID - Frontend: All existing frontend code using
useCurrentUser()continues to work - Backend: Other services should use
/users/{user_id}for user data
Files Modified
services/auth/app/api/auth_operations.py- Removed endpointfrontend/src/api/services/user.ts- Updated service methodfrontend/src/api/client/apiClient.ts- Updated endpoint configuration
Verification
All changes have been verified with the verification script and pass syntax checks.