axios-auth-refresh
axios-auth-refresh copied to clipboard
Retry of the original request fails only if GET request
Hi, this is my configuration
const sendRequest = axios.create({
baseURL: import.meta.env.VITE_SERVER_URL,
withCredentials: true
})
const refreshAuthLogic = (failedRequest) => sendRequest.post('/admin/refresh').then(() => {
setUserInfo(prev => ({
...prev,
logged: true,
}))
return Promise.resolve()
}).catch(error => {
//se non va a buon fine butto fuori l'utente
setUserInfo({
logged: false,
info: {}
})
return Promise.reject(error);
});
// Instantiate the interceptor
createAuthRefreshInterceptor(sendRequest, refreshAuthLogic);
my tokens are all saved in cookies.
The problem is that if the original request is a POST request it works. But if the original request is a GET the retry request after the refresh request fails with this error:
DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'function(header, parser) {
header = normalizeHeader(header);
if (!header)
return void 0;
const key = findKey(this, header);
if (key) {
const value = this[key];
if (!parser) {
return value;
}
if (parser === true) {
return parseTokens(value);
}
if (utils_default.isFunction(parser)) {
return parser.call(this, value, key);
}
if (utils_default.isRegExp(parser)) {
return parser.exec(value);
}
throw new TypeError("parser must be boolean|regexp|function");
}
}' is not a valid HTTP header field value.
I don't know if i miss something or there is a bug.
thank you.
@GiovanniSlabs am stuck with the same error and still looking for solutions. Did you find out? let me know, please)
Hi @olksndrdevhub, yes after many test i find out that this problem is due to a bug in the new version of axios > 1.0.0
The error is when axios try to set the header in retring the failed request
axios(request_options).then(() => {
...
}).catch(error => {
const originalRequest = error.config;
return axios(originalRequest) // here it messes up in setting the header correctly
});
So using v0.27.2 of axios solve the problem.
Thanks for catching that @GiovanniSlabs
Any solutions to fix this instead of downgrading axios version?