tRPC

T

tRPC

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

Join

Difference in type inference for vanilla client?

Hello, querying an endpoint with the vanilla tRPC client but at runtime the actual result isn't the inferenced type but {json: ..., meta: ...}, am I doing something wrong?

Zod Error Middleware

Hey lovely people. At Cal.com we make heavy use of zod for data validation. I was wondering if there's a way to create some kind of "error middleware" that can catch all Zod specific errors and serve the proper TRPC error back to the client. This would allow us to just use schema.parse instead of having to manually check schema.safeParse or having to use try/catch everywhere. Thanks for any input! šŸ™...

clear cookie onError

I'd like to clear a cookie (in nextjs) when a 403 error happens. I've been looking at the global error handling: https://trpc.io/docs/error-handling#handling-errors and this looks like the right place, except that I don't have access to the response , which would be needed to clear a cookie. Is there a better place to do this, or is there a reason there is no access to the res ?...

Mutation with react-hook-form

Hello I'm trying to use mutation with react-hook-form. In the form, I will have to give interface of the input that I want, so I'm wondering whether it's possible to get the type of input to some mutation from trpc and pass it as input type.

Request context from getServerSideProps

The docs of tRPC context https://trpc.io/docs/v10/context
export async function createContext(opts: trpcNext.CreateNextContextOptions) {
export async function createContext(opts: trpcNext.CreateNextContextOptions) {
...

Auth with passport.js

Evening all,
Has anyone successfully setup trpc with passport.js for auth?...

Object keeps getting overwritten

I feel like i'm missing something fundamental here. when I add a new entry into object b it resets to an empty object upon a subsequent request. Can anyone help? ```js addNewTicket: ticketsDomainProcedure .input( z.object({...

AccessToken for API calls

What would be the best approach to pass the AccessToken from NextAuth Session to the Http Client which is being called from tRPC procedures to access external API?? Should I attach the AccessToken to the request object from NextAuth session callback and then provide it to the HttpClient instance in the tRPC context initialization for the request?? Or is there better alternative to handle this?...

Request or Response Specification Definition Document

I am developing a backend service using trpc, but I need to dispatch trpc in another programming language. I would like to know the design specification of trpc related requests and responses so that I can implement it in other languages....

abortOnUnmount config error

I'm encountering an error when passing abortOnUnmount saying that it does not exist as a possible param. I'm basing this off the v10 docs. Am I missing something here? My implementation: ```ts const [trpcClient] = React.useState(() =>...

zustand + trpc (basic data fetching)

im trying to use zustand with trpc, but having trouble setting some data to global state. What am i missing here? ```js import create from 'zustand'; import { trpc } from '../../utils/trpc';...

First time learning trpc really good tool. help with setting cookies on front end.

Hello how do you use tRPC to make a cookie and send it to the front end. or is there any other method to make some auth stuff with the next auth.

How do we add settings in each query like before?

Since the new update, bee super confused. I used to do this, and can't recreate it now. ``` const { data: traitz, isLoading,...

Handling error globally

According to the docs on errors https://trpc.io/docs/v10/error-handling I should get such error object on client side when its thrown from procedure If I understand correctly. But Im having a problem with it as it doesnt seem to be typed as TRPCError on the client and dont contain few props from described in docs. ```js queryCache: new QueryCache({ onError: async (error: any) => {...

cant access trpc endpoints via the browser

i'm converting some express endpoints to trpc, and I cant figure out how to access my endpoints via the browser for example http://localhost:3000/trpc/getbytenantid my trpc endpoint ```js...

tRPC without SSR

When using tRPC with ssr it uses getInitialProps, which has kinda of a cool effect in terms how a page is rendered, since it's rendered server-side on initial requests and client-side on route transitions. Unfortunately, enabling ssr means that you can no longer use getServerSideProps (which I know is only fixable by next.js and not tRPC). But how to replicate the getInitialProps behaviour then? Let's say I'm building a blog; due to SEO it's basically necessary to render my posts server-side. But when navigating through the site loading posts on the fly would be totally fine. How to do that without ssr?...

trpc + expo react native issue

Does anyone know how to solve this? Im not familiar with webpack at all. I’m a junior frontend....

Can you chain middlewares in v10?

Would I be able to make a rate limit and isAuthed middleware, then put queries behind both middlewares so it's rate limited and protected by auth? The docs suggest it doesn't work like this, but I wanted to make sure.

Load data client-side via react-query while using tRPC with SSR

Is there any way to load data client-side when using tRPC? I want my page to be rendered and load data dynamically, since this data is not SEO-relevant. As far as I'm understanding as soon as I turn on SSR in tRPC queries must be done before the page is rendered.