diff --git a/modules/frontend/src/api/AuthClient/AuthClient.ts b/modules/frontend/src/api/AuthClient/AuthClient.ts index c7c20dd..2619db9 100644 --- a/modules/frontend/src/api/AuthClient/AuthClient.ts +++ b/modules/frontend/src/api/AuthClient/AuthClient.ts @@ -25,6 +25,7 @@ const baseClient = createClient(createConfig({ baseUrl: '/api/v1 export const authClient: Client = { ...baseClient, + // Force the function to match the expected signature exactly request: (async < TData = unknown, TError = unknown, @@ -35,30 +36,22 @@ export const authClient: Client = { Pick>, 'method'> ): Promise> => { + // Initial request let result = await baseClient.request(options); - // 1. Cast to a Record to allow the 'in' operator check on a generic - // We use 'unknown' instead of 'any' to maintain safety. - const resultObj = result as Record; + // Check for 401 + if ((result as any)?.error?.response?.status === 401) { + const refreshed = await getRefreshed(); - // 2. Check if the object is valid and contains the error key - if (result && typeof result === 'object' && 'error' in resultObj) { - - // 3. Narrow the error property specifically - const error = resultObj.error as { response?: { status?: number } } | null | undefined; - - if (error?.response?.status === 401) { - const refreshed = await getRefreshed(); - - if (refreshed) { - result = await baseClient.request(options); - } else { - localStorage.clear(); - window.location.href = "/login"; - } + if (refreshed) { + // Retry + result = await baseClient.request(options); + } else { + localStorage.clear(); + window.location.href = "/login"; } } - return result; - }) as Client['request'], + return result as RequestResult; + }) as Client['request'], // Cast the function itself to match the Client interface }; \ No newline at end of file