title: How to send authorization header with axios
body: <p>How can I send an authentication header with a token via axios.js?
  I have tried a few things without success, for example: </p>
  
  <pre><code>const header = `Authorization: Bearer ${token}`;
  return axios.get(URLConstants.USER_URL, { headers: { header } });
  </code></pre>
  
  <p>Gives me this error: </p>
  
  <pre><code>XMLHttpRequest cannot load http://localhost:8000/accounts/user/. Request header field header is not allowed by Access-Control-Allow-Headers in preflight response.
  </code></pre>
  
  <p>I have managed to get it work by setting global default, but I'm guessing this is not the best idea for a single request: </p>
  
  <pre><code>axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
  </code></pre>
  
  <p><strong>Update :</strong> </p>
  
  <p>Cole's answer helped me find the problem. I am using <strong>django-cors-headers middleware</strong> which already handles authorization header by default. </p>
  
  <p>But I was able to understand the error message and fixed an error in my axios request code, which should look like this </p>
  
  <pre><code>return axios.get(URLConstants.USER_URL, { headers: { Authorization: `Bearer ${data.token}` } });
  </code></pre>