is 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.
Nick
Nick197d ago
You can use a async function to set headers in the trpc client, that’s generally the best place to make this call
Tom
Tom197d ago
im not sure how that solves the problem. that would allow me to send headers to the server but i need to call this function on the client unless, are you saying theres a function that will set headers before?
Nick
Nick197d ago
This is definitely in the docs, headers IS a function You can pass just an object but a function returning an object is also correct
More Posts
How to refetch a call made on the server```js const section = await api.course.getCourseSection.query({ sectionId: parseInt(params.lessoHow to set cookies in trpc response?I have an app dir project that was created using [this t3-app PR](<https://github.com/t3-oss/create-Check if Role is ADMINHey guys I have a private procedure in `T3 Stack`. I need to check if the user thats doing the actioCan middleware be used on a router?Given a router where all procedures need to use the same middleware, can the middleware be somehow aHow can I use `onSettled` in the `experimental_createTRPCNextAppDirClient`?**Context** I want to migrate the following trpc/client hook to the experimental version ```ts consStop initial refetch when prefetched with SSG helpersAnyone else struggling with this, I want to maintain refetching when the tab is refocused but don't Accessing QueryFunctionContext within server queriesHello, I know that the field 'direction' is a new addition within react query v5 as part of the QueHTTP 431: Input too longHi, we're using a complex query (multiple filters etc) with tRPC and react query integration. It hFunction to release context post-batching?In our application every customer has their own schema, therefore we need a db client per request whforwarding headers in solidjsI have a setup with solidstart, and im trying to forward the client headeres to ttrpc. Here's my seSupport @tanstack/react-query 5.4.3will it support 5.4.3 @tanstack/react-query when i install above version with my next.js it unable tHelp with inferring output```ts return ctx.prisma.product.findMany({ include: { price: { select: { Would you recommend tRPC’s usage in this case?So we have two applications, one existing, one about to be started. These two applications will talkHow to limit payload size?Is there a way to limit the payload size? E.g., if a particularly large JSON payload is sent to the