Skip to content
New issue

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

triger cors when work with swr #72

Open
yizhilee opened this issue Apr 7, 2023 · 0 comments
Open

triger cors when work with swr #72

yizhilee opened this issue Apr 7, 2023 · 0 comments

Comments

@yizhilee
Copy link

yizhilee commented Apr 7, 2023

I have registered an interceptor in my app.js file in react as follows:

fetchIntercept.register({
  response: function (response) {
    if (response.status >= 500 && response.status < 600) {
      bottomToast("server error")
    }
    return response;
  }
});

However, when I use SWR to fetch data, I encounter a CORS error. Here's the code I'm using for the fetch:

const fetcher = (...args) => fetch(...args, { headers:{ accessToken: state.accessToken } }).then((res) => res.json())
const {data: profile} = useSWR(state.isLogin ? `${portalAddress}/user/${state.userId}` : null, fetcher);

It seems that the OPTIONS request is being sent before the fetch request, which is causing the CORS error.
It's important to note that this issue only occurs in production mode and not in the development environment. The error message I receive is shown in the attached screenshot.

image

@yizhilee yizhilee changed the title ttriger cors when work with swr triger cors when work with swr Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant