Synchronization issue with fetching library #12424
Unanswered
Johncena-Huang
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description:
I’m using
next-auth
withuseSWR
for data fetching, and I'm trying to set up an Axios interceptor to add an Authorization token to the request headers. However, I’m encountering a synchronization issue whereuseSWR
is firing before I reset the axios interceptor(My current approach doesn't work, the sync is fired after useSWR invokes fetcher function).Steps to Reproduce:
useSWR
to fetch data with Axios.Authorization
header with the token fromnext-auth
'suseSession()
.useSWR
is called before the axios interceptor is reset.Code Example:
Global setup
My fetcher
How the fetcher is used
Expected Behavior:
when useSWR calls the fetcher, axios instance interceptor should already be synchronized with useSession. Any approach suggested to handle this issue?
Environment:
Beta Was this translation helpful? Give feedback.
All reactions