I use swr to fetch user data. The request is accompanied by cookies.
The fetcher is configured for cors request as follow:
const fetcher = async (url: string, params?: any) => {
const res = await fetch(url, fetchConfig)
return handleResponse(res)
}
with fetchConfig as:
{
credentials: 'include',
mode: 'cors'
}
The first request is sent correctly with cookies, but the subsequent requests are sent without cookies, which results in failed(401) request.
I browsed the network tab of browser console and found out that:
- The first request is "initiated" by above fetcher snippet.
- The subsequent requests are "initiated" by
web-preset.jsas follows:
var fetcher = function (url) { return fetch(url).then(function (res) { return res.json(); }); };
Notice it's not using the configuration. Does anybody have an idea why this is happening, or why the configured fetcher is not used at all except the first time?