Replies: 1 comment
-
did you ever find a nice solution for this? looking for the same. I'm usually using hooks and zustand to store the accessToken in memory to build my axiosPrivate fetcher, which wont work in this case, it seems. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
Hi, I was thinking about switching to SWR over just using axios but I stumbled upon an issue with the authentication of my app. It uses JWT authentication where the refresh token is stored as a httpOnly cookie on the client, and the access token is stored in memory on the client.
When a request to an endpoint which requires authentication returns a 403 status, a response interceptor that has been applied to the axios instance attempts to refresh the users tokens using the refresh token. It also applies a new header to the request to imply it has already been sent, as to prevent an infinite loop if the server again returns a 403 status. If the server does return with the new access token, then we append that to the Authorization header on the original request and retry it.
Now my question is how would you implement this using SWR? Could you use the onErrorRetry option to achieve the same thing?
I have done my fair share of googling but I have yet to find a discussion on it, so I appreciate any input!
Beta Was this translation helpful? Give feedback.
All reactions