NeoBean
NeoBean12mo ago

Forward client headers with createTRPCProxyClient & Server-Side Helpers

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() } }
}
4 Replies
NeoBean
NeoBean11mo ago
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 ?
settapak.t
settapak.t11mo ago
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
dion
dion9mo ago
did u find a solution for this?
NeoBean
NeoBean9mo ago
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.
More Posts