[Bug] Duplicate fetch/API client logic between api/client.ts and utils/api.ts #6

Closed
opened 2026-08-16 06:34:42 +00:00 by nasandre · 1 comment
Owner

Problem
The frontend has two separate API client implementations with overlapping functionality:

  1. frontend/src/api/client.ts (324 lines) — Class-based ApiClient with apiClient instance, exports authApi, characterApi, campaignApi, shipApi, mcpClient
  2. frontend/src/utils/api.ts (140 lines) — Function-based baseFetch/authFetch with its own characterApi, authApi, campaignApi, shipApi exports

Neither imports from the other. The Zustand stores (characterStore.ts, shipStore.ts, campaignStore.ts) import from @/api/client, but useAuth.ts:69-70 and useAuthStore inline their own fetch() calls. This creates:

  • Code duplication
  • Potential inconsistency in error handling and base URL configuration
  • Confusion about which client to use

Proposed fix
Consolidate to a single API client. Recommend keeping api/client.ts (it's more complete and is what the stores already import from), and either:

  • Remove utils/api.ts entirely and migrate useAuth.ts/useAuthStore to use api/client.ts
  • Or re-export from one module as the single source

Priority: Medium
Labels: refactor, frontend, cleanup

**Problem** The frontend has two separate API client implementations with overlapping functionality: 1. `frontend/src/api/client.ts` (324 lines) — Class-based `ApiClient` with `apiClient` instance, exports `authApi`, `characterApi`, `campaignApi`, `shipApi`, `mcpClient` 2. `frontend/src/utils/api.ts` (140 lines) — Function-based `baseFetch`/`authFetch` with its own `characterApi`, `authApi`, `campaignApi`, `shipApi` exports Neither imports from the other. The Zustand stores (`characterStore.ts`, `shipStore.ts`, `campaignStore.ts`) import from `@/api/client`, but `useAuth.ts:69-70` and `useAuthStore` inline their own `fetch()` calls. This creates: - Code duplication - Potential inconsistency in error handling and base URL configuration - Confusion about which client to use **Proposed fix** Consolidate to a single API client. Recommend keeping `api/client.ts` (it's more complete and is what the stores already import from), and either: - Remove `utils/api.ts` entirely and migrate `useAuth.ts`/`useAuthStore` to use `api/client.ts` - Or re-export from one module as the single source **Priority:** Medium **Labels:** refactor, frontend, cleanup
Author
Owner

✅ Resolved by #39 (commit 05b5453) — utils/api.ts deleted; api/client.ts is now the single API layer. Closing.

✅ **Resolved** by #39 (commit `05b5453`) — `utils/api.ts` deleted; `api/client.ts` is now the single API layer. Closing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nasandre/wh40-rogue-trader#6
No description provided.