tRPC

T

tRPC

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

Join

Clearing Cache

How do I clear the queryCache for a particular query using the trpc context? If that's not possible, how can I do that using queryClient?
queryClient.getQueryCache().clear()
queryClient.getQueryCache().clear()
I've tried the above but it clears the entire cache. I just want to clear the cache of particular key....

context at times empty

am new to trpc. i am usin iron-session with nextjs and its awesome. am forwarding the context. but sometimes session is empty. then it reload and session is not empty. tried it with static data. this doesnt happen with static data. any ideas? i have followed the trpc docs for adding trpc to an existing nextjs application.

query and mutate promise on next

I've followed the guide "Usage with Next.js" and now I only have the useQuery and use useMutation hooks exposed when I want to call a route. How do I also expose the regular query and mutate promises on these routes? Edit: Solution: ```...

testing a trpc hook

i'm brand new to testing and need some help with writing a test for a hook that is returning an object. im stuck with the error messages. i'm using trpc and react query ```js export function useGetTenantTickets() { const setTickets = useTenantStore((state) => state.setTickets); const { isLoading, isError } = trpc.ticketDomain.getByTenantId.useQuery(...

CAS Authentication

So long story short. My University is using CAS as authentication provider. I was thinking that I could use NextAuth with it to authenticate my users but I have no clue how am I supposed to do that. They don't support OAuth2 because they have old version of CAS. I asked on GH discussion in NextAuth for help but didn't get any. I also tried seeking help on Theo's discord twice this month but no luck. I don't know what to do and I feel like people working there have no clue what to do. I really want to be using TRPC with NextJS as I love this combo but how on earth can I authenticate my users using something like this? I was told I could use this lib https://www.npmjs.com/package/node-cas-client...

save return type to type var

Hello, I want to save the type that return from useQuery to type variable. For example, I have this complex return type from the query and would like to do something like type userInfoType = object. Please point me to some direction. Thank youuuuu ❤️...

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.