tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

trying to understand how this works

so i'm looking at the t3 template that was made for me, and there seems to be a trpc folder that creates the trpc proxy client and such along with server/api which actually defines the method in that case, what's the use for the api route? it seems to me like i'm initialiting trpc twice, basically...

can't call nested route

this is the top level router: ```ts const appRouter = router({ hello: procedure.query(() => 'hello world'), chess: chessRouter,...

trpc auth

Did someone create a full auth system in trpc (with next js trpc react query prisma,jwt token, refresh token)and wants to share his code??

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. ...

Merging two clients into one

I have two clients. One for react-query for client components and one for server components. I wanna be able to call .query() or .useQuery() from the same object so you get one object for API calling on both server and client. I tried combining the two client objects with Object.assign. The types work as you can see in the screenshot but the object returned from Object.assign is empty. Wanna know what's the reason for that or what's the better way of doing this...
No description

Is it possible to only use WebSockets when necessary, otherwise use httpbatch or http?

I have an application, and on certain pages I need live data. Is there a way to only have tRPC open a websocket for subscriptions and then use another link otherwise? I would like for the solution to disconnect from WS when all subscriptions have been ended, so no dangling WS connections....

Zod transform types

I have a zod type for our backend requirements that looks like this: ```javascript const ZCustomType = z.object({ nameFirst: z.string(), nameLast: z.string(),...
No description

useQuery in App Router?

I have a client component that I want to use useQuery in like in pages router, but only query is available
Solution:
where are you importing api from? You have to make sure you import it from /trpc/react.ts

Tranform output data using middleware after handler has run - possible?

As the title says, been trying for a couple of hours to modify the return type of the data using middleware. So far unsuccesful. The idea: Handler returns data, audit middleware logs the full entity, then pipe through another middleware that transforms the full entity into some DTO. DX wise the nicest solutions I have come up so far is using the middleware pipe:...

Can we configure cache on a per-request basis?

Hi! I’m a big fan of tRPC! I’ve been using it for quite some time. I actually have 2 questions: 2) Can we use the Next.js cache and revalidate fetch options with tRPC on a request level? ...

Error in tRPC with Clerk in t3-app router

Hi guys, im trying to implement clerk auth in t3 app router. But it gives me this error when im trying to query: errorrfile: This is my repository link https://github.com/CsarChvz/t3-approuter-clerk-error I mean even...

Error when converting string from router.query to prisma DB enum

Hey yall, I'm working on a Next.js application using tRPC and Prisma, and I've encountered an invalid_enum_value error when trying to filter service providers by category in my listing.getAll procedure. Here's the error message I'm receiving: ``` tRPC failed on listing.getAll: [ {...

Next.js tRPC router separated to edge-runtime and node-runtime

I would like to separate server into two runtimes - most things can run on edge-runtime, but I have some endpoints that need nodejs api. It is easy to have two vanilla clients, but can i combine two clients into one react-query client?...

[How To?] Create a record in database on form submission...

I have an application using trpc, Cloudfare D1 database, and trpc. I am trying to use a tamagui form component to insert a record into the database. My trpc route:...

How to obfuscate data via transformer

End user with adequate knowledge can easily copy JSON data in plain text from network requests in browser dev tools. I'd like to make copying JSON data a bit more difficult for these advance users. Looks like obfuscation needs to be done in transformer. Does anyone have ideas how to implement obfuscation along with superjson within transformer?...

Response delay from TRPC using postgresql

I'm using TRPC as backend and for the database using postgresql so while creating using facing delay issue let me explain throw by example. I created products table it has it one data while creating another product after that I checked on postgresql new product added on prodcuts table but while fetching from TRPC it's not getting 2 products while I have to wait for around 15-20 seconds then I can get 2 products data how can I fix this issue....

Capture TRPCClientError so that it does not show in the client's browser console

If a TRPCError is thrown from a router procedure, the client will receive a TRPCClientError that will display in the client's browser console. Is there any way to capture this error so that it does not show in the client's browser console?

Netlify function EMFILE

If this is a dumb question just point me in the direction of the stackoverflow. I've scoured discord and github issues to see if I can find any similar issues to no avail. I've got a t3 server set up right now with a few TRPC method calls from the frontend to the backend. Everything is fine locally where my open file limit has not been modified from my stock OS config. ...

empty `input` object when using mutation

When using useQuery I have no issues even with input but when using useMutation. The backend is receiving an empty input. What could be the reason? stack is nodejs + express + reactjs + yarn Frontend code...

Returning html with TRPC

Is it possible to return content-types other than JSON, so HTML for example? I have a requirement that needs it.