We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have encountered strange behavior when accessing endpoints with bearer token. I have a fetcher like this:
const fetcherWithToken = async (url, token) => { try { const response = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token }, }) let text = await response.text() const data = text ? JSON.parse(text) : null if (response.ok) { return data } else if (response.statusCode === 401) { const error = new NotAuthorizedError(response.statusMessage); error.status = response.status throw error } const error = new Error(response.statusText) error.response = response error.status = response.status error.data = data throw error } catch (error) { if (!error.data) { error.data = { message: error.message } } throw error } }
and a hook like this:
const { data, error } = useSWR( ["https://api.example.com/xxx", token], fetcherWithToken, { refreshInterval: 5000 } );
After token refresh SWR keeps refreshing with both tokens - the old and the new.
I would expect SWR to refresh only with the new token.
Source code: https://codesandbox.io/s/eager-hoover-v4ryk?file=/pages/index.js
swr: 0.3.11
I have come across this problem when building next.js application with @react-keycloak/ssr.
PS: I am not a JS developer so the code is a mess and it might just be PEBCAK.
The text was updated successfully, but these errors were encountered:
add test for vercel#852
f4b5b93
Thank you
Sorry, something went wrong.
add test for #852 (#855)
62ccce3
* add test for #852 * improve assert
Successfully merging a pull request may close this issue.
Bug report
Description / Observed Behavior
I have encountered strange behavior when accessing endpoints with bearer token. I have a fetcher like this:
and a hook like this:
After token refresh SWR keeps refreshing with both tokens - the old and the new.
Expected Behavior
I would expect SWR to refresh only with the new token.
Repro Steps / Code Example
Source code: https://codesandbox.io/s/eager-hoover-v4ryk?file=/pages/index.js
Additional Context
swr: 0.3.11
I have come across this problem when building next.js application with @react-keycloak/ssr.
PS: I am not a JS developer so the code is a mess and it might just be PEBCAK.
The text was updated successfully, but these errors were encountered: