QueryCache error handling and axios headers refresh #7945
Unanswered
michailozdemir
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there. I have a some sort of issue in my project.
I use some public API and a token in order to use the API requests.
There's a certain possibility where the token can be outdated or stored inside the session storage, but the corresponding tool on the server side could disable it and etc. There's no refresh token request, so I have created a certain workaround inside my QueryClient provider.
But as you see, there's a weird thing I have to do. I have to set the headers to my axios instance twice and I'll explain why.
Once a certain batch of requests are being failed, we get into this piece of a code, where we re-fetch the token. Once it is done, we set a new headers and do the invalidateQueries(). Once that's done, my application goes further and on the next request the query still has old token value. Then we again get inside this error handling part and re-fetch the token again (though we shouldnt) and so on.
If I do the redundancy with the headers setting up after invalidation - everything works as expected. Could someone provide an explanation on to fix that without a weird hacky solutions? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions