Reputation: 359
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:
web-preset.js
as 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?
Upvotes: 2
Views: 658
Reputation: 359
It turns out I was actually using swr inside global swr config. Obviously configs are not in effect yet, so the default fetcher was being used.
Upvotes: 0