Tom
Explore posts from serversis there a way to do client-side "middleware"?
My app uses Firebase Auth for authentication. While the user is logged in, they get an ID token which is valid for 1 hour (non-configurable). The front-end is supposed to call a function
await user.getIdToken()
to refresh this token.
Is there a way that I can have the frontend try a request, examine the response, potentially call this function if the server tells me the token is expired, and then retry? I want this to happen without triggering the onError() callback for all of my queries / mutations if possible.7 replies
working with custom errors and trpc errorFormatter
Hey guys. I'm trying to refactor my app so that all errors extend a BaseError class to make dealing with error codes and user-friendly messages easier. I'm having trouble converting these to the correct shape in the tRPC errorFormatter. Right now when I throw these custom errors tRPC doesnt recognize them and converts all of them to INTERNAL_SERVER_ERROR's.
I see that some error codes get translated in 3 places: the jsonrpc error code, the http status code, and an HTTP status,. There also seems to be some additional structure. My end goal is to be able to convert my errors to the 'normal' shape so that trpc-openapi can correctly return them.
Is there a reasonable way to do this in tRPC or should I do something different?
Its easy enough for me to convert one of my errors to a TRPCError, but I don't see a way to convert that to the right shape once I'm in the errorFormatter. is there a way to do this?
29 replies
How to prefetch data on the client into the cache?
To simplify a bit, lets say I'm making an app that allows users to view a project. I have a top level UI route with a summary of the project and then sub-routes that display more details, some of which require more fetches. Is there a way that I can make it so that when the top-level route loads, the trpc cache automatically prefetches the data needed for the sub-routes?
Whenever I search the site for 'prefetch', I find the SSR stuff, but I'm actually trying to prefetch on the client.
Thanks.
18 replies
is there a way to call useQuery() from a callback and get the return value within that callback?
I have a generic component that is effectively an autocomplete that fills in options from a web request. The component takes a callback which takes in the newest search string and should perform a web request to get the autocomplete options and return them. Is there a way I can call a trpc
useQuery()
and get the return value within this async callback? Thanks.11 replies