import type { AppRouter } from "@labas/api/routers/index"; import { env } from "@labas/env/web"; import { QueryCache, QueryClient } from "@tanstack/react-query"; import { createTRPCClient, httpBatchLink } from "@trpc/client"; import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query"; import { toast } from "sonner"; export const queryClient = new QueryClient({ queryCache: new QueryCache({ onError: (error, query) => { toast.error(error.message, { action: { label: "retry", onClick: query.invalidate, }, }); }, }), }); export const trpcClient = createTRPCClient({ links: [ httpBatchLink({ url: `${env.VITE_SERVER_URL}/trpc`, fetch(url, options) { return fetch(url, { ...options, credentials: "include", }); }, }), ], }); export const trpc = createTRPCOptionsProxy({ client: trpcClient, queryClient, });