tRPC

T

tRPC

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

Join

Async User Call in `createContext` (context.ts) or in `isAuthed` (in trpc.ts)

Hi all! Should I be getting the user in all requests via createContext in the following async call
const { user } = await supabaseAdmin.auth.api.getUserByCookie(opts.req)
const { user } = await supabaseAdmin.auth.api.getUserByCookie(opts.req)
Or would it be more sensible for this to only be called in certain procedures such as middleware like isAuthed? In theory, I don't want public API calls being slower because of the delay it takes to fetch the user....

'req' of undefined in onError of express middleware

I've recently noticed that I get a bunch of errors regarding req object missing in ctx for onError property in trpc express middleware. Can't figure out how req obj might be undefined at the point of onerror handler?? ```js app.use( '/trpc',...

Mutations and Queries in React Contexts causing unexpected behaviors

In my organization, we recently moved to put all of our mutations/queries into React Contexts and out of components (NextJS with React 18). I am now seeing requests and debouncing behaviors that used to work no longer work.
In some cases it appears we now have race conditions as loading/success are not necessarily being handled, but in other cases we're not getting reactivity from mutations that are in contexts Anyone else have experience or tips re: throwing tRPC stuff into React Contexts?...

Custom error management

Hey peeps! I could've sworn I created a GitHub issue about this, but I must've been dreaming, because I cannot find it. Anyway, it's support-related, so I figured it's better to ask here! I have a large application that has a traditional client/server API and I use Axios to make calls to the server. Now, I'm investigating replacing that with tRPC (because it feels like an amazing developer experience and will quicken development). I have a rather "sophisticated" error management in the application. I have my own custom ApplicationError, which has an errorCode and a custom data object with additional information about the error. Any server-side code in the application can throw this error. A middleware catches this and converts it to a 400 Bad Request with an appropriate JSON response body. In the client, I also have my custom wrapper on top of Axios, that simply catches 400 Bad Request, and converts the JSON back to an ApplicationError and simply throws it. This means that I can easily catch ApplicationError in my client side code, just as if it was originally thrown on the client....

How can I generate trpc Generic Types?

I am building a trpc library, and as part of my implementation, I need the generic types of t, t.mergeRouters, t.procedure, t.router and t.middleware. I've haven't been able to locate those generic types in the @trpc/server and since trpc has such a complex type structure, would love to see an implementation for a generic set of types for the ones listed about....

context question

Why are the context examples only showing opinionated examples with next/react auth ? Also i find it very confusing that it is not mentioned in the docs what kind of arguments the context function is called with.

async middleware

is it possible to define an async middleware? I want to do something like this but it throws errors when i start the server const dbMiddleware = middleware(async ({ path, ctx, next, input }) => { ...

errorFormatter ignored when using appRouter.createCaller

My errorFormatter works correctly in the actual application using an adapter, e.g. ``` trpcExpress.createExpressMiddleware({ router: appRouter, createContext: createTRPCContextFromExpress, }),...

Is there a way to define the Websocket protocol when using wsLink()

I am attempting to use tRPC with Azure's Pub/Sub Websockets service it appears to require custom protocols to be defined as explained here: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/reference-json-webpubsub-subprotocol They give the following code example: ```js var pubsub = new WebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', 'json.webpubsub.azure.v1');...

The inferred type of this node exceeds the maximum length the compiler will serialize.

Hey, there I am running into this error when I have more than 12 routers in the mergeRouters function. The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. version: latest related: https://github.com/trpc/trpc/issues/2568 // that din't work for me....

Quickstart not working

Hello there, There is a type error in the quickstart example if i'm not mistaken. I pretty much copy - pasted the example into my monorepo but i'm getting the following error in the client....

Use TRPC function inside of a TRPC function

Hi all! We have a trpc query called getProduct. I want to use this getProduct query inside of another query (getCart query). Is this possible / simple as a single trpc request rather than multiple?

Supabase with trpc

When trying to configure trpc with supabase, getting this kind of error in the console tRPC failed on <no-path>: Invariant: Method expects to have requestAsyncStorage, none available The message is kind of cryptic, does anyone have an idea what this relates to?...

Using tRPC for uploading audio files

I want to create an api router in tRPC but am not sure if the following code is doable with tRPC. If yes can you point me to a resource where I can learn how to do it? ```ts import FormData from "form-data"; import { withFileUpload } from "next-multiparty"; import { createReadStream } from "fs";...

Express middleware router type isn't correct

I am trying to build an adapter for nestjs, this adapter needs to add the express middleware but for some reason the router type isn't going through and it seems that the AnyRouter type isn't compatible. I've attached some photos of the implementation and the error. Thanks!...

Enigmatic INTERNAL SERVER ERROR

Im having a problem finding out about what is causing the INTERNAL SERVER ERROR from tRPC in my production. This is the error 👀 ```js { "level": "error",...

createProxySSGHelpers type error

Hi all! Anyone know how to use createProxySSGHelpers with appropriate createContext typing?

Can I force metadata with the createCaller?

I have custom metadata which I check within the middleware. Im trying to write tests for this. Currently no single procedure is using the meta and I wonder If I can test this somehow. Can I add meta on the fly to the procedure with createCaller?? ``` const t = initTRPC .context<typeof createTRPCContext>()...

Vitest error test

How can I test for specific TRPCError code with vitest? I managed to get the message but can't figure out how to get the code. ``` it('should throw if user roles are missing', async ({ trpcContextMock }) => {...