Difference between createTRPCNextAppDirServer, createTRPCNext and createTRPCProxyClient?
Hey everyone.
I struggle to understand the difference between these 3 TRPC functions when it come to using it in server.ts to be able to make server side API calls.
I'm using NextJS 14 and app router.
Is there clear differentiation between these 3?
This project is for a production release.
Would greatly appreciate a little break down.
Thanks!
13 Replies
I belive you are talking about initTRPC, initTRPCBrowser, and initTRPCServer, right ?
I'm referring to step 3 from the docs.
https://trpc.io/docs/server/data-transformers
Currently I'm using the following structure to make server side calls to my database:
I don't quite get what benefit I'd get if I was to use createTRPCNextAppDirServer or createTRPCNext instead of createTRPCProxyClient as all of them are capable of making server side calls.
Data Transformers | tRPC
You are able to serialize the response data & input args. The transformers need to be added both to the server and the client.
The difference between createTRPCProxyClient, createTRPCNext, and createTRPCNextAppDirServer lies in their use cases and intended usage scenarios.
createTRPCProxyClient:
Use Case: This is intended for client-side usage. It allows you to create a client proxy that can be used on the client to make tRPC queries. It's suitable for scenarios where you need to make requests from the client to the server.
createTRPCNext:
Use Case: This is designed for server-side usage within Next.js API routes. It provides an instance of TRPCClient specifically configured for server-side rendering (SSR) within Next.js.
createTRPCNextAppDirServer:
Use Case: This is a variant of createTRPCNext but is specifically intended for server rendering within Next.js when your api directory is within your app directory.
In summary
Use createTRPCProxyClient for client-side usage.
Use createTRPCNext for server-side rendering within Next.js API routes.
Use createTRPCNextAppDirServer if your API directory is within your app directory and you want server-side rendering in that specific setup.
I hope it helps
Also, have u ever create a full auth system with trpc next and jwt ?
Thanks a lot for the detailed answer!
No, I haven't. That's what I'm trying to do atm with Next, TRPC and Supabase Auth.
Any time
Ohh…I am trying for days
And nothing
Also Supabase setup?
No, I use mongodb
What are you having problems with?
After I log in, I can not send my custom headers to my context
With that context I check if user has a token
And then he can access protected procedures
If u solve auth…can u share the git ?
Sure
@Ignition 98
any idea why is not store in cookie ?
![No description](https://cdn.answeroverflow.com/1173330407832432831/image.png)
No idea tbh..