umi-request
umi-request copied to clipboard
Cannot set headers in request interceptors
Hey! I have a problem with the request interceptors. I'm trying to add headers (for jwt auth), but the request sends without provided. Maybe someone has similar problems?
const request = extend({
errorHandler,
prefix: API_URL,
});
request.interceptors.request.use((url, options) => {
const token = getAuthToken();
options.headers = {
...options.headers,
'Accept-Language': getCurrentLocale(),
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
};
// now in options.headers we have all provided headers and return them
// but umi-request just ignore headers and don't add them to the request
return {
url,
options,
};
});
same bugs, and if set headers in interceptor, will miss orgin and get CORS error
I have solved an issue. I had 2 clients of umi-request and I think somehow they block each other interceptors.