refactor: centralize frontend auth query gating

This commit is contained in:
2026-08-25 14:29:41 +03:00
parent fff36f252a
commit 268acdf2e1
24 changed files with 352 additions and 82 deletions
@@ -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 EventsEndpoint =
@@ -7,17 +6,14 @@ type EventsEndpoint =
export type BrokerageEvent =
EventsEndpoint["responses"][200]["content"]["application/json"]["events"][number];
export function useBrokerageEvents(
accountId: string | undefined,
accessToken: string | null,
) {
return useQuery({
export function useBrokerageEvents(accountId: string | undefined) {
return useAuthenticatedQuery({
...apiQueryClient.queryOptions(
"get",
"/api/v1/brokerage-accounts/{accountId}/events",
{ params: { path: { accountId: accountId ?? "" } } },
),
enabled: Boolean(accountId && accessToken),
enabled: Boolean(accountId),
staleTime: 30_000,
retry: false,
});