umi-request icon indicating copy to clipboard operation
umi-request copied to clipboard

Cannot set headers in request interceptors

Open nesymno opened this issue 4 years ago • 2 comments

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,
  };
});

nesymno avatar May 15 '21 10:05 nesymno

same bugs, and if set headers in interceptor, will miss orgin and get CORS error

coader avatar May 28 '21 09:05 coader

I have solved an issue. I had 2 clients of umi-request and I think somehow they block each other interceptors.

nesymno avatar May 29 '21 18:05 nesymno