tRPC

T

tRPC

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

Join

AppRouter Type Declaration Method

Is there a method where I can manually define the AppRouter Type outside of importing the AppRouter from the Server as a type? I'm running a more complex monorepo structure and am trying to create a shared type package/module but, if I import the AppRouter as a Type it will create a circular dependency. Ideally, I basically just created a bunch of procedure objects and then stacked them together and was trying to create a base level understanding of the AppRouter as a Type to pass to TRPC Clients that I make. If I am unable to do it this way, I suppose I could just create a seperate shared module for the trpcClient then import it from the server in that seperate module and utilize that module to create Clients per service... But I would prefer to just define my trpcClient within the services as the type of client varies by the service....
No description

Where should authorization/permissions checks happen?

Hey there 👋 What is generally the preferred place to perform permissions checks? Using meta, within a procedure method, within the definition of the procedure via middleware, or something else? I initially opted for performing checks within defined procedure methods, but this results in quite a bit of code duplication, so I figure using meta could be better (it does feel intuitive). Yet, this somehow feels non-standard. I haven't seen this before... in an ideal world this permissions object could be passed into a procedure as an arg alongside the handler/method as a kind of augmentation. Currently, I am exploring the use of meta to do this:...

export full declaration of AppRouter for use in another project

So I have my API server and my web app. They're separate projects and initially I can import AppRouter type with relative paths but it feels messy, but it's ok. Now I have implemented some app specific typescrpt resolve/alias for imports, all my types break as the web project can't resolve those aliases that are present in the api project without sharing the same aliases. I wonder if there is some way to codegen export type AppRouter in to a full declaration that is standalone? Then I can just import that one file without it needing to understand the layout of the other project? Any help appreciated ❤️...

File uploads / downloads

https://github.com/trpc/examples-next-formdata I found this, does this mean it's possible to have file uploads and downloads with trpc now? Does it use chunking or does it put everything into memory.

Setting up open-telemetry

My backend uses fastify + tRPC. What’s the best way to setup open-telemetry. Any repo references would be great. Thanks!

middleware’s for routers

I am using middleware’s in procedures presently. I want to use middleware’s for the whole child router to handle multi-tenancy & role-permission handling. Is there a way to add middleware’s directly to child routers?...

Why did the usage change in that way?

Bit of a general question. Is there a blogpost or a video talking about that? I personally liked the old usage in the component much better: Old ```typescript...

Can I use tRPC with Tanstack Start while fetching or performing mutations from an external API?

Hello everyone! I really appreciate tRPC, particularly its type safety when making function calls between the client and server. In my current project, I'm utilizing external API endpoints for fetching data and making POST requests. Example: ```...

Next.js App router

Hello, is there any official way to implement tRPC with app router, or is it still experimental, according to the example app repo I came across? Any guidance would be appreciated 🙂 Thanks....

Network request was successful, variable was not populated

I'm fetching the data, json is being returned, but trying to use this data is impossible
Solution:
``` const t = initTRPC.context<Context>().create({ transformer: superjson, errorFormatter({ shape, error }) { return {...
No description

TRPCError: Missing content-type header

Hi, i haven't been using trpc in a while, i'm trying o setup TRPC on a fastify backend and react frontend. I followed the example from the doc but when react tries to fetchs some data i get the following error: ``` Error in tRPC handler on path 'undefined': TRPCError: Missing content-type header at getContentTypeHandler (/Users/andreabenfatti/Dev/tmp/fastify-test/node_modules/.pnpm/@trpc+server@11.0.0_typescript@5.8.3/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.js:221:11)...
Solution:
Right after asking the question I found the problem. It something that has to do with CORS. I solved it using vite proxy to forward the request to the server and now everything works as expected

How to add recaptcha support

Hello! I am looking to add ReCaptcha v3 support to a few of my trpc endpoints. I am not able to find any reference to how I can do this. I am using create-t3-app...
Solution:
The same way you’d with any api right? You could make use of a “reusable base procedure”. https://trpc.io/docs/server/procedures#reusable-base-procedures...

Prisma ESM (node-postgres) / tRPC 11 / Next.js 15 issue

Hi everyone! Key components of our stack: - Prisma 6.9.0 (with pg adapter)...

Preventing action from throwing error due to zod schema?

I have trpc creating server actions, fronted by a zod form data schema. ``` const createDatasetSchema = zfd.formData({ name: zfd.text(...

Caching a middleware response during batching

Hey there, I do some authorisation checks in middleware (procedure) - the authorisation check is a little bit slow. I'm facing an issue that when the page initially loads, there is a significant amount of TRPC requests sent as a batch and although it's sent as a batch, each path still runs the procedure. Is there a way to cache the procedure response for the same request, or use the same procedure output for multiple requests during a batch?...

Limit payload size on specific routes?

When using TRPC, is there a way to limit payload size on specific routes? E.g, for a route that accepts base64 encoded images, I would like to limit the maximum body size to 10mb. For all other routes, I'd like to limit the maximum body size to 1mb....

Custom hooks v11

Is there a successor to inferReactQueryProcedureOptions in the updated react-query integration or what's the recommended way to infer the query options for custom hooks now?

event emitter doesnt trigger subscription from webhook

I'm using subscription in nextjs using SSE, im trying to trigger subscription when webhook receives data, webhook is seprated page api/webhook/route.ts and subscription is in root.ts, I even tested subscription using little mock of mutation and subsciption procedures and it was working fine, here is the test which works ✅ ```js test: createTRPCRouter({...

Track mutation status in other react components?

Is there a way to check a mutation isPending in another component from the on it was called in? I can see the useUtils providers a isMutating() function. But I tested and it doesn't seem to be changing. This is v11

Zod Output validation failed

Hello, i'm using trpc and for some reason the return statement passes the type checks but at runtime it fails the zod validation, why?