Luiz F. A. Morais
TRPCClientError: Unable to transform response from server
utils/trpc.ts
providers.tsx
export const trpc = createTRPCReact<AppRouter>();
export const trpc = createTRPCReact<AppRouter>();
const transformer = superjson;
let token: string;
export const setToken = (newToken: string) => {
token = newToken;
};
export default function Providers({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(() => new QueryClient({}));
const url = process.env.URL ? process.env.URL : "http://localhost:5000/trpc";
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url,
fetch(url, options) {
return fetch(url, {
...options,
credentials: "include",
});
},
headers() {
return {
Authorization: token ? `Bearer ${token}` : "",
};
},
}),
],
transformer: transformer,
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
}
const transformer = superjson;
let token: string;
export const setToken = (newToken: string) => {
token = newToken;
};
export default function Providers({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(() => new QueryClient({}));
const url = process.env.URL ? process.env.URL : "http://localhost:5000/trpc";
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url,
fetch(url, options) {
return fetch(url, {
...options,
credentials: "include",
});
},
headers() {
return {
Authorization: token ? `Bearer ${token}` : "",
};
},
}),
],
transformer: transformer,
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
}
4 replies