Kylar
Kylar
Explore posts from servers
TtRPC
Created by Kylar on 1/24/2024 in #❓-help
How can i createCaller from a NextJs App Router if my server uses express tRPC adapter?
I ended up creating a wrapper around createTRPCProxyClient that grabbed the cookies and injected the authToken into trpc using httpBatchLink like so:
export const createTRPCServerClient = async () => {
const authToken = ""; // Grab from cookies
return createTRPCProxyClient<AppRouter>({
transformer: superjson,
links: [
httpBatchLink({
url: "http://your-url.com/api/trpc",
headers: {
...(authToken ? { authorization: `Bearer ${authToken}` } : {}),
},
}),
],
});
};
export const createTRPCServerClient = async () => {
const authToken = ""; // Grab from cookies
return createTRPCProxyClient<AppRouter>({
transformer: superjson,
links: [
httpBatchLink({
url: "http://your-url.com/api/trpc",
headers: {
...(authToken ? { authorization: `Bearer ${authToken}` } : {}),
},
}),
],
});
};
8 replies