title: How to send JWT token with fetch and cors to an Express server in Authorization headers?
body: <p>I can retrieve JWT token from localStorage and send it in the <code>req.body</code> but for some reason, I'm unable to send it to the server with fetch() in <code>headers.Authorization</code>. I can log the token on the client-side but don't receive it on the server. </p>
  
  <p>Client: React, Redux-Saga. </p>
  
  <pre><code>function* getInitialStateFetch(){
  
    var actionType = 'GET_INITIALSTATE_REDUCER';
    var path = 'react/listings28';
  
    var token = localStorage.getItem('my_tkn');
    console.log(token) // logs token
  
    var httpHeaders;
  
    if(token){
    httpHeaders = { 
      'Content-Type' : 'application/x-www-form-urlencoded', 
      'Accept' : 'application/json',
      'Authorization' : `Bearer ${token}`
    };
    } else {
      httpHeaders = { 
        'Content-Type' : 'application/x-www-form-urlencoded', 
        'Accept' : 'application/json'
      };
    }
  
    let options = {
      method: 'GET',
      mode: 'no-cors',
      headers: new Headers(httpHeaders),
      credentials: 'same-origin'
    };
  
    yield call(apiCall, path, options, actionType);
  }
  </code></pre>
  
  <p>apiCall.js</p>
  
  <pre><code>export default function* apiCall(path, options, actionType){
  
    try {
      const response = yield call(fetch, `http://blah/${path}`, options);
      const data = yield call([response, response.json]);
  
      // call reducer
      yield put({type: actionType, payload: data});
    } catch (e) {
      console.log(e.message);
      console.log(`error api call for ${actionType}`);
    }
  }
  </code></pre>
  
  <p>Server: Express.</p>
  
  <pre><code>router.get('/react/listings28', parserFalse, (req, res)=&gt;{
  
  
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3333');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
    res.setHeader('Access-Control-Allow-Credentials', true);
  
    var token = req.headers.Authorization; // nothing here
  
    console.log(`req headers below`);
    console.log(req.headers); // no Authorization here
  }
  </code></pre>
  
  <p>req.headers screenshot from the server</p>
  
  <p><a href="https://i.stack.imgur.com/PDLuL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PDLuL.png" alt="req.headers screenshot from the server"></a></p>