diff --git a/frontend/src/contexts/ConfigContext.tsx b/frontend/src/contexts/ConfigContext.tsx index 63e1e91..63af8e1 100644 --- a/frontend/src/contexts/ConfigContext.tsx +++ b/frontend/src/contexts/ConfigContext.tsx @@ -51,14 +51,6 @@ export function ConfigProvider({ children }: { children: ReactNode }) { fetchConfig(); }, []); - if (isLoading) { - return ( -
-
-
- ); - } - return ( {children} diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 1a01b6b..2cde149 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,6 +1,6 @@ import { toast } from "sonner"; import { Job } from "./types"; -import { getApiUrl, getBackofficeUrl } from "./config"; +import { getApiUrl, getBackofficeUrl, initConfig } from "./config"; // API Base URL - now uses runtime config // Fetched from /api/config at runtime, falls back to build-time env or defaults @@ -16,6 +16,9 @@ function logCrudAction(action: string, entity: string, details?: any) { * Generic API Request Wrapper */ async function apiRequest(endpoint: string, options: RequestInit = {}): Promise { + // Ensure config is loaded before making request + await initConfig(); + // Token can be stored as 'auth_token' (from auth.ts login) or 'token' (legacy) const token = localStorage.getItem("auth_token") || localStorage.getItem("token"); const headers = { @@ -572,6 +575,9 @@ export const profileApi = { // Backoffice URL - now uses runtime config async function backofficeRequest(endpoint: string, options: RequestInit = {}): Promise { + // Ensure config is loaded before making request + await initConfig(); + const token = localStorage.getItem("token"); const headers = { "Content-Type": "application/json",