Closed mittci closed 2 years ago
Header is set wrong (not with set)
console.log('check', ctx.options.headers.get('X-XSRF-TOKEN'), ' | ', ctx.options.headers['X-XSRF-TOKEN']) return check null | xLk4607R-q2iUfqGACIYWmLdZiQvCaBmyPBQ
In @refactorjs/ofetch is config.headers[config.xsrfHeaderName] = decodeURIComponent(cookie); but need to be config.headers.set(config.xsrfHeaderName, decodeURIComponent(cookie)); And like in ohmyfetch config.headers = new Headers(config.headers) before
That will be
addXSRFHeader_fn = function(config) {
const cookie = getCookie(config.xsrfCookieName);
const cookies = getCookies();
if (config.credentials === "include" && config.xsrfCookieName && cookies[config.xsrfCookieName]) {
config.headers[config.xsrfHeaderName] = decodeURIComponent(cookie);
}
return config;
};
Like so
addXSRFHeader_fn = function(config) {
const cookie = getCookie(config.xsrfCookieName);
const cookies = getCookies();
if (config.credentials === "include" && config.xsrfCookieName && cookies[config.xsrfCookieName]) {
console.log('addXSRFHeader_fn', config.headers)
if (config.headers.constructor.name === 'Object') {
config.headers = new Headers(config.headers)
}
// config.headers[config.xsrfHeaderName] = decodeURIComponent(cookie);
config.headers.set(config.xsrfHeaderName, decodeURIComponent(cookie));
}
return config;
};
Need some changes like so https://github.com/refactorjs/ofetch/pull/1
Environment
nuxt 3 last
Reproduction
https://github.com/Maxp777/nuxt3_2
Describe the bug
When make a call to api XSRF-TOKEN header are set and no 403 csurf error. After press login and all work well.
But if refresh page and press login (without call to some api point) XSRF-TOKEN header are not set.
Additional context
At first api call when press login XSRF-TOKEN is present in cookies in section request header
Logs
But
useNuxtApp().$auth.loginWith('local', { body: { email: 'mail@mail.com', password: '123qwe' }})
result inNo response