tRPC

T

tRPC

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

Join

Parsing FormData on trpc

Hi all, I have function to put object on S3 const putObjectToS3 = async (body: FormData) => { ......

TRPC to connect a client app with a backend apigateway ?

Hi everyone! Is it a good practice to use TRPC to connect my client application (Next.Js) with my backend RESTful APIGateway app (Nest.Js) that plays a role of an entry point to other micro-services. Are there best practices for such use cases ? ...

Websocket server implementations with TRPC createWSClient

Is anyone aware of a websocket server that is compatible with trpc websocket client that isn't using the subscriptions example with applyWSSHandler function? I'm planning to implement a WSS server in Go to be compatible with createWSClient as I've been struggling to implement the full websocket nextjs example on github with the recent changes made to T3 app with regards to createTRPCContext, next headers, next auth providers functions not being defined etc. If people are aware of server implementations it could save me some time implementing my own....

Advanced Permissioning In Middleware

I need to handle somewhat complicated permissioning logic, for example: User A can read (but not write) tasks from Facility B Is there a good pattern for applying this sort of logic in middlewares? Currently, I can create a verbose permission set in Context for that user, but I'm not sure how best to handle a facility-specific route, for example trying to read tasks from Facility B. ...

How is the Client Generated with just the types

I'm trying to build a trpc like app for building restful apis with sveltekit. In trpc sveltekit only the type is passed to the client fucntion and how is the client object typically created with just the type?

Generate iOS Swift tRPC client

Hey all, I'm looking to get pointed in the right direction for how to best generate a native tRPC client for a Swift iOS app that shares a tRPC backend with a web app. I've seen @Alex / KATT 🐱 loosely mention generating a Swift client based on a tRPC app router (https://twitter.com/alexdotjs/status/1721812788010451302 and https://twitter.com/alexdotjs/status/1706396243415515446) but can't find any further information....

Middleware that returns data instead of throwing error

Is there any way for a middleware to return typed data instead of throwing an error? I can only see examples of the latter. I'm thinking about something like this: ```ts...

Including multi-tenant config into tRPC context

Hey all, I've been working on upgrading my app to support multi-tenancy, inspired by Vercel's Platforms starter kit. The core of the relevant logic comes down to this Next.js middleware:...
Solution:
For anyone who stumbles upon this later, my fix for now is to do this: ```ts export async function createContext( ctx: CreateWSSContextFnOptions | CreateNextContextOptions,...

Suggestion to deal with external dependencies on backend side?

Hello, i have a question about dealing with external dependencies inside mutations and queries on the backend side. For example i have a route which is doing something, i can add for example database dependency inside the context so in the route i can use
ctx.db...
ctx.db...
This is fine as long as i want to use it with tRPC all the time. But since there is a lot of things changes and evolves in the world of JS everyday i would like to be a bit agnostic from external packages. If for example tRPC will be not be widely used 10 years later, it would be nice to just copy everything from the router and paste it somewhere else, and it will work like that because my code not rely on any external dependency which comes from the trpc context. What do you think about this? How do you deal with this?...

TRPC & Zod Logging

I'm building a backend and if my input validation fails I want to log the failure but couldn't figure out a way as trpc seems to handle the error straigth away, anyone know how this could be done?

How to handle Query Errors on client side (show toast on 401)

Hey ! Hope you're doing well ! I wanted to know if someone can explain to me how to handle errors on the client (using Next.js). I need to handle UNAUTHENTICATED error on client because when a user tries to access a resource I want to display a feedback toast. Thanks 🙏...

TRPCClientError: JSON Parse error: Single quotes (') are not allowed in JSON

I am getting this error when deployed but not when running locally.
TRPCClientError: JSON Parse error: Single quotes (') are not allowed in JSON
TRPCClientError: JSON Parse error: Single quotes (') are not allowed in JSON
...

How to access isLoading if a Query is inside a component

I am having trouble in accessing isLoading from a query, the problem is that the Query is placed inside a component

tRPC and vite serverless, are there any exmaples?

Now that tanstack router is out I would want to move out of nextjs, but keep the convenience of hosting on vercel with serverless. I saw that theres some vite-vercel plugin (vite-plugin-vercel) for SSG/ISR/serverless functions, but not sure how I would integrate it with tRPC. are there any exmaples for something like that?...

How can i use inferprocedureoutput?

I'd like to write this code type-safely:```ts const handleQuery = (query: /* ? */) => {} const MyComponent = () => { const query = trpc.foo.useQuery()...

Can a URL be formatted with dashes, such as "user-list" in the context of trpc?

Can a URL be formatted with dashes, such as "user-list" in the context of trpc?
const appRouter = router({
userList: publicProcedure.query(async () => {
const appRouter = router({
userList: publicProcedure.query(async () => {
...

Incorrect type inference with discriminated unions.

Hey folks, I am having a really weird issue. Here is a minimal reproducible example: https://tsplay.dev/WJB1kW Basically I have a function that returns an object of the Difference, which is a union of 3 other types:...

Get Query Key on Server

I'm following some recommended practices from one of the react query maintainers @tkdodo and want to invalidate queries from the server in a type-safe way. As a result of this I want to be able to get the query keys for queries on the server to properly invalidate them using a trpc subscription. Is there a clean way to feed the router definition into getQueryKey? At the moment what I'm doing is: ```ts /**...
Solution:
I wouldn’t couple the backend into the frontend state management by trying to dispatch the query key. Instead dispatch a message relevant to your business logic, and on the frontend turn that into a query key for invalidation and optimistic updates, you’ll have a better time

ReferenceError: Cannot access 'appRouter' before initialization

Hi friends im having trouble implementing a "protected" or "private" procedure in TRPC using Next.js 14 with NextAuth.

trpc openapi does not work on app router

https://github.com/jlalmes/trpc-openapi Can i just know if trpc open api for next is also applicable for app router, the repo has example for pages router but not for app router, i tried to replicate that to app router but it is failing by something like this [get-computers is just an api endpoint]...
No description