refactor: centralize frontend auth query gating
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiQueryClient } from "@/shared/api";
|
||||
import { apiQueryClient, useAuthenticatedQuery } from "@/shared/api";
|
||||
import type { paths } from "@/shared/api/generated/schema";
|
||||
|
||||
type OperationsEndpoint =
|
||||
@@ -37,17 +36,16 @@ export function brokerageOperationsQueryParams(
|
||||
|
||||
export function useBrokerageOperations(
|
||||
accountId: string | undefined,
|
||||
accessToken: string | null,
|
||||
query: BrokerageOperationsQuery = {},
|
||||
) {
|
||||
const params = brokerageOperationsQueryParams(query);
|
||||
return useQuery({
|
||||
return useAuthenticatedQuery({
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/operations",
|
||||
{ params: { path: { accountId: accountId ?? "" }, query: params } },
|
||||
),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
enabled: Boolean(accountId),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user