Tom
Tom14mo ago

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.
3 Replies
Nick
Nick14mo 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
TomOP14mo 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
Nick14mo 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