tRPC

T

tRPC

Join the community to ask questions about tRPC and get answers from other members.

Join

Question about onError and modifying error messages in tRPC

I’m trying to follow the tRPC docs on error handling and want to log detailed errors on the server by throwing specific exceptions but send a generic message to the client (see https://trpc.io/docs/server/error-handling#handling-errors). I thought this would work: ``` onError: (opts) => {...
Solution:
You want the errorFormatter

tRPC does not have headers data when refreshing.

I'm using tanstack-start, tRPC and better-auth in my project and have it setup like this ```ts export async function createContext(opts: CreateNextContextOptions) { const session = await auth.api.getSession({ headers: opts.req.headers }); ...

Unref() the websocket

Hello everyone, What I desire is to use a websocket link but not have TRPC hold the process open indefinitely, preventing my Node.js script from finishing (as is default when you have a websocket connection open). If you merely unref() the underlying socket then the process quits before the query/mutation finishes. The following is my working solution, but I'm wondering if there was a simpler/more elegant solution:...

what is the format/type of data received in transformer.deserialize in httpBatchStreamLink?

trying to write a query normalizer to work together with react-query, and was hinted that i could use transformer to do it, but the format of data received in transformer.deserialize is puzzling, sometimes i receive an object, sometimes an array and sometimes nested array promises, plz help

trpc caching procedure calls for queries in the same batch

Hello, I am using nextjs and trpc server components, using trpc to prefetch queries. All of the requests on this page are protected by a procedure called protectedGuildPermissionsProcedure which essentially checks that the user has the right permissions to access the data that is returned. ```ts await Promise.all([...

How do I fetch data conditionally?

Sorry if this is a stupid question. I know that there is the mutation queries to do some actions and queries for getting data. I need to get data conditionally, I don't need to get a certain data but only on some specific event, I don't know if there's an option for that like the useMutation and useQuery. I've tried fetch, but it seems like I don't use the right client configuration? ```ts...
No description

What is the type of the query resolver?

I need to accept queries in my function, like this one: const somt = t.task.admin.lessons What is the type of this somt variable? Imagine I am passing it as argument to some function, I need to know the type of the argument I should use....

SSE issue with CORS and Fastify

Hello, I've followed the guidelines here (https://trpc.io/docs/server/subscriptions) but my useSubscription calls don't go through. Thoughts? ``` const server = fastify({ maxParamLength: 5000,...

mutation taking a long time to appear after prefetching query

Hello, I'm am currently having an issue where if my isCaptchaValid endpoint errors (using throw new TRPCError(...)) the error message takes a long time to come through, it appears that it is linked to the endpoints execution time, as if I add some code to wait 2 seconds before executing it dramatically increases the time it takes for the error to come back. I am using nextjs loading.tsx which is how the loading animation works, so as soon as the loading animation is gone it means that TRPC data has finished fetching, so the error message should be appearing instantly?...

Server actions leaking .env

Ive got some router for generated presigned s3 urls. router: https://pastebin.com/zSQ4MRjK (its not meant to be a public procedure) I created an actions file like this:...
No description

When upgrading to v11, the AppRouter in .d.ts is any

Hello ! I just tried to upgrade from trpc v10 to trpc v11. I am on a monrepo, the the tRPC router type is built as part of a package. ...

Does batch streaming get counted as a single function invocation on Vercel?

I'm wondering if the batched http call gets counted as one on vercel?

how can I set up trpc to work with nested providers?

Hi, I have two separate clients with their own typings and HTTP links, and I wrap my application in nested providers—one for each client—with their own QueryClient instances. However, regardless of which client I use, the runtime always sends the request to the URL specified in the innermost provider. The typings and client definitions appear correct, but at runtime both clients' queries are routed to the endpoint of the innermost provider. ...
No description

Calling endpoint within another endpoint

Hi, I need to get the result of one of my endpoints, but I can't just call the underlying function directly — because every endpoint is wrapped with security and middleware before being exposed through the tRPC appRouter. So instead of bypassing those layers, I need to trigger the full chain — essentially making a proper call to the endpoint itself (as if it were external), even from inside another tRPC procedure. ...

[Typescript] Client query / mutate has any type

I've broken my tRPC routes into separate modules and combined them using mergeRouters, but that seems to have broken type-safety on the client. Now, trpc is showing up as any, and I’ve lost all autocomplete and type hints for available procedures. Things I’ve checked: - I’ve gone through the tRPC FAQ and verified everything listed. - Types were working fine (only for health-check procedures though) before I split and merged the routers ...
No description

What do you call the function that is used by a procedure?

Hey all! I'm making a small style guide for my team and was wondering what to call the actual function that is passed to procedures... should I also call it a procedure?

wsLink with external (custom) websocket?

I want to integrate an external websocket to tRPC for extra type-safety with wsLink where the url will need to be dynamic and the authentication as well. The problem is as follows: 1) The websocket url is dynamic. It needs to be requested through an API first to get it, because the system has multiple nodes with different ports....

Error trying to serve TRPC from custom path in Hono

I'm successfully serving a basic "hello world" using the default root path: ```proxyApp.use("/trpc/*", trpcServer({ router: appRouter,...

Next JS error handling.

I'm having this weird error in Next dev whenever I throw an error in a router. ``` login: publicProcedure.input(loginSchema).mutation(async ({ ctx, input }) => { const { error } = await ctx.supabase.auth.signInWithPassword({...
No description

bigint

My trpc client is showing type never for bigints. How can I fix this? Thanks...
Next