title: How do I access a global variable after it has been stored locally?
body: <p>I am having issues using a local variable outside of the function. I am making a call to myapi.com/access_token to obtain the access token and then I need to use that access token in the header of my request to the jsonserverprovider. I have tried declaring it with window.bl_token but I still get a result of undefined when I attempt to console.log the response. </p>
  
  <pre><code>import React from 'react';
  import { fetchUtils, Admin, Resource } from 'react-admin';
  import jsonServerProvider from 'ra-data-json-server';
  
  var bl_token;
  
  const data = { email: 'xxx@xxx.com', password: 'xxx' };
  
  fetch('https://myapi.com/access_token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  })
  .then((response) =&gt; response.json())
  .then((bl_data) =&gt; {
    window.bl_token=bl_data.access_token;
  })
  
  const httpClient = (url, options = {}) =&gt; {
    if (!options.headers) {
        options.headers = new Headers({ Accept: 'application/json' });
        options.headers = new Headers({Authorization: bl_token});
  
    }
    return fetchUtils.fetchJson(url, options);
  };
  
  const dataProvider = jsonServerProvider('https://myapi.com/', httpClient);
  const App = () =&gt; (
      &lt;Admin dataProvider={dataProvider}&gt;
          &lt;Resource name="links"/&gt;
     &lt;/Admin&gt;
  );
  export default App;
  </code></pre>