diff --git a/src/hooks/api/authenticated-query-v2.ts b/src/hooks/api/authenticated-query-v2.ts index db29e4bfa..2c2a136e7 100644 --- a/src/hooks/api/authenticated-query-v2.ts +++ b/src/hooks/api/authenticated-query-v2.ts @@ -26,9 +26,10 @@ type GenerateQueryKeyArguments = { type GeneratedQueryKey = readonly [QueryKey, QueryArguments]; -type AuthenticatedQueryFunctionContext = +type AuthenticatedQueryFunctionContext = QueryFunctionContext & { headers: HeadersInit; + queryArguments?: TQueryArguments; }; type ServerSideOptions = { @@ -41,8 +42,11 @@ type PrefetchAuthenticatedQueryOptions = { } & ServerSideOptions & FetchQueryOptions; -type UseAuthenticatedQueryOptions = { - queryArguments?: QueryArguments; +type UseAuthenticatedQueryOptions< + TQueryFnData, + TQueryArguments = QueryArguments, +> = { + queryArguments?: TQueryArguments; } & Omit< UseQueryOptions, 'queryFn' @@ -75,31 +79,18 @@ const getPreparedOptions = ({ options, isTokenPresent, headers, -}: GetPreparedOptionsArguments): UseQueryOptions< - TQueryFnData, - FetchError, - TQueryFnData, - GeneratedQueryKey -> => { +}: GetPreparedOptionsArguments) => { const { queryKey, queryArguments, queryFn, ...restOptions } = options; const generatedQueryKey = generateQueryKey({ queryKey, queryArguments, }); - const queryFunctionWithHeaders = async ( - context: QueryFunctionContext, - ) => { - return await queryFn( - context, - // @ts-expect-error - headers, - ); - }; return { ...restOptions, queryKey: generatedQueryKey, - queryFn: (context) => queryFn({ ...context, headers }), + queryArguments, + queryFn: (context) => queryFn({ ...context, queryArguments, headers }), ...('enabled' in restOptions && { enabled: isTokenPresent && !!restOptions.enabled, }),