T
tRPC

❓-help

Forward client headers with createTRPCProxyClient & Server-Side Helpers

NNeoBean8/26/2023
With createTRPCNext i had the option to tap into the context.req object nextjs passed in, but I cant achieve the same with createTRPCProxyClient. For example below code fails authentication, cause cookies arent forwarded.
export const getServerSideProps: GetServerSideProps = async ctx => {
ssHelpers.user.profile.prefetch(undefined, { context: ctx })
return { props: { trpcState: ssHelpers.dehydrate() } }
}
export const getServerSideProps: GetServerSideProps = async ctx => {
ssHelpers.user.profile.prefetch(undefined, { context: ctx })
return { props: { trpcState: ssHelpers.dehydrate() } }
}
My helpers. No access to the context here. The headers function has some opList array, with query keys and an empty context
const proxyClient = createTRPCProxyClient<TRPCRootRouter>({
links: [
httpBatchLink({
url: `${process.env.NEXT_PUBLIC_API_HOST}`,
}),
],
transformer: superjson,
})

export const ssHelpers = createServerSideHelpers({
client: proxyClient,
})
const proxyClient = createTRPCProxyClient<TRPCRootRouter>({
links: [
httpBatchLink({
url: `${process.env.NEXT_PUBLIC_API_HOST}`,
}),
],
transformer: superjson,
})

export const ssHelpers = createServerSideHelpers({
client: proxyClient,
})
Is this something not implemented ?
Ssettapak.t9/22/2023
how use ? my console.log('user ===>', user) /// result : undefined how fix
export async function getServerSideProps() {
const { user } = await helpers.auth.getInfoUser.fetch();
console.log('user ===>', user);
return {
props: {
trpcState: helpers.dehydrate(),
},
};
}
export async function getServerSideProps() {
const { user } = await helpers.auth.getInfoUser.fetch();
console.log('user ===>', user);
return {
props: {
trpcState: helpers.dehydrate(),
},
};
}
@neobean
Ddion11/2/2023
did u find a solution for this?
NNeoBean11/2/2023
I'm sorry i did not at that time I didn't need it at very much, so i just used trpc client-side I'll retry this in the coming days.

Looking for more? Join the community!

Recommended Posts
I have a websocket + REST project. Should I be using splitLink like this to combine WS and HTTP?I have a backend project that uses REST for queries/mutations and Websockets for subscriptions. I jNested procedures are separated by dots, is there a way to change that to `/`s instead ?currently it looks something like this `/api/trpc/post.byId`, is there a way to have it like `/api/tIs there a way to split a trpc api across multiple lambdas ?How do I go about splitting my TRPC api across multiple lambdas, such that each lambda would load thCan I alter the context in a procedure?Is there a proper way to do this? Mutating the `opts.ctx` directly seems wrongtRPC & getInitialPropsSo I am not using Next new App router but cant figure it out how to call a method during SSR with geGetting 413 error in Vercel when batching several queries (using Next pages router)Hi guys, I'm having a weird error on Vercel: "LAMBDA_RUNTIME Failed to post handler success responsQueries work but mutations do notOdd bug I'm experiencing with TRPC + react-query + the koa adapter. I just set everything up per docuseContext utils getData always returning undefinedI have my app set up with TRPC and when trying to call ` const utils = trpc.useContext();` `consTRPC Error HandlingI am using TRPC as my backend for my nextjs application. The one major problem i am facing is that, CORS issue with Lambda Handler (SST)no idea what's going on with this error. been stuck on it for way too long. i tried adding the test-TRPC API not working for production buildI am using Trpc and next in project, The App is fully functional with dev build , but api's giving 4Get object type using UseTRPCQueryResultthis code ```ts type playlistOutputData = UseTRPCQueryResult< inferRouterOutputs<AppRouter>["notifNeed help with type hinting a function that accepts a trpc client router```js interface CreateModelProps<GetResult> { name: string, procedures: DecoratedProcedureReDatabase error on examples-next-prisma-starterHi, im on node 18.16.0. I'm trying to clone and use this : https://github.com/trpc/examples-next-priSet server response headers from TRPC standalone adapterHi I am trying to implement my own authentication in Trpc. For this I need to create a session on tReturn TRPC Error from NextJS middlewareI am using trpc for my app's api but Im using NextJS middleware + upstash ratelimitting for.... well