MonkeyStruct
Using TRPC Server Caller in client side.
What's up TRPCer.
so i'm currently working in vanilla react app with seperate backend in .NET, in previous projects i have used Next with TRPC server and honestly loved DX with it so i wanted to implement it for the react app and parse .NET server response in TRPC route func and utilize @trpc/server pkg that way and use createCaller instance to use like almost server/query func. intention was to use tanstack react query and trpc routes as basically queryFn.
Seems like that wont work tho. trpc throws not allowed to use server func in client side error.
Is there a way to make it work? or TRPC requires a server implemented with trpc server.
1 replies
createTRPCNext config ctx always returns undefined.
Hi Everyone.
So I'm trying to use TRPC and Nextjs for auth and post query etc. I have client side createTRPCNext below.
when i try to access ctx in config opts it always returns undefined. type says it is NextPageContext | undefined, so i'm guessing i'm missing something. Please let me know if you guys have any ideas.
Also, if you have any idea on using http-proxy with trpc server for cookie assignment etc would be amazing. I been trying to set cookies in proxy server and following this blog's steps https://maxschmitt.me/posts/next-js-http-only-cookie-auth-tokens
With proxy route simple queries works but when i selfHandleResponse and return response, I get TRPCClientError. Thank you for all the help!
5 replies
createTRPCNext type error
Hi everyone. So I started creating nextjs app with trpc + prisma set up. and when i use my AppRouter type with createTRPCNext I get "The types returned by createCaller(...) are incompatible between these types." error
this is whole error msg and I'm not sure if you guys have seen it!
6 replies
tRPC context and NextJS
Guys quick question about using trpc and nextjs. I'm using context with trpc to create some queries that will be only accessible by logged in users. On nextjs side I'm using react context to manage it for now. So my thinking was to pass one of the ctx variable that will be user ID to trpc server when I use useQuery. Ex) trpc.user.getSecret.useQuery(undefined, {req.body}). But I'm honestly stuck on how I can send next request body. Code for trpc context is this.
I know you can change body in api/[trpc] route but I won't have access to ReactContext there so if any of you guys have a suggestion or solution please let me know. 🙏🙏🙏
4 replies