File size: 1,196 Bytes
2b62b0c cfc59e4 81d2e69 cfc59e4 81d2e69 cfc59e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import type { AppRouter } from "@pram/api/routers/index";
import { env } from "@pram/env/web";
import { QueryCache, QueryClient } from "@tanstack/react-query";
import { createTRPCClient, httpBatchLink, TRPCClientError } 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) => {
if (
error instanceof TRPCClientError &&
(error.data?.code === "UNAUTHORIZED" ||
error.message.toLowerCase().includes("authentication required"))
) {
return;
}
toast.error(error.message, {
action: {
label: "retry",
onClick: query.invalidate,
},
});
},
}),
});
export const trpcClient = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: `${env.VITE_SERVER_URL}/trpc`,
fetch(url, options) {
return fetch(url, {
...options,
credentials: "include",
});
},
}),
],
});
export const trpc = createTRPCOptionsProxy<AppRouter>({
client: trpcClient,
queryClient,
});
|