Files
bakery-ia/CHANGES_SUMMARY.md
2026-01-16 15:19:34 +01:00

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/me endpoint (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/me from noTenantEndpoints array
  • Before: /auth/me was listed as a user-level endpoint
  • After: Removed since the endpoint no longer exists
  • Note: /auth/me/onboarding remains 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

  1. Consistency: Single source of truth for user data
  2. Simplicity: Removes redundant endpoint
  3. Maintainability: Clearer API structure
  4. Performance: No duplicate data fetching logic

Testing

  • Created verification script to ensure all changes are syntactically correct
  • Verified that /auth/me endpoint 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/me will 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

  1. services/auth/app/api/auth_operations.py - Removed endpoint
  2. frontend/src/api/services/user.ts - Updated service method
  3. frontend/src/api/client/apiClient.ts - Updated endpoint configuration

Verification

All changes have been verified with the verification script and pass syntax checks.