Files
beenvoice/src/trpc/query-client.ts
Sean O'Connor a1b40e7a9c Add Turso/Vercel deployment configuration
- Updated database connection to support Turso auth token
- Added vercel.json with bun build configuration
- Updated environment schema for production deployment
- Added new features and components for production readiness
2025-07-12 01:42:43 -04:00

62 lines
1.7 KiB
TypeScript

import {
defaultShouldDehydrateQuery,
QueryClient,
QueryCache,
MutationCache,
} from "@tanstack/react-query";
import { TRPCClientError } from "@trpc/client";
import { toast } from "sonner";
import SuperJSON from "superjson";
export const createQueryClient = () =>
new QueryClient({
queryCache: new QueryCache({
onError: (error) => {
if (
error instanceof TRPCClientError &&
error.data &&
typeof error.data === "object" &&
"code" in error.data &&
(error.data as { code: string }).code === "UNAUTHORIZED"
) {
toast.error("Please sign in to continue");
if (typeof window !== "undefined") {
window.location.href = "/auth/signin";
}
}
},
}),
mutationCache: new MutationCache({
onError: (error) => {
if (
error instanceof TRPCClientError &&
error.data &&
typeof error.data === "object" &&
"code" in error.data &&
(error.data as { code: string }).code === "UNAUTHORIZED"
) {
toast.error("Please sign in to continue");
if (typeof window !== "undefined") {
window.location.href = "/auth/signin";
}
}
},
}),
defaultOptions: {
queries: {
// With SSR, we usually want to set some default staleTime
// above 0 to avoid refetching immediately on the client
staleTime: 30 * 1000,
},
dehydrate: {
serializeData: SuperJSON.serialize,
shouldDehydrateQuery: (query) =>
defaultShouldDehydrateQuery(query) ||
query.state.status === "pending",
},
hydrate: {
deserializeData: SuperJSON.deserialize,
},
},
});