title: How to make initial authenticated request with token from local storage?
body: <p>I'm using vanilla flux with some <code>utils</code> for communicating with my APIs.</p>
  
  <p>On initial page load I'd like to read some token from local storage and then make a request to my API to get my data.</p>
  
  <p>I've got a <code>LocalStorageUtils.js</code> library for interacting with <code>window.localStorage</code>. My container component handles all login/logout actions and reads the current user on page load.</p>
  
  <p><code>App.js</code></p>
  
  <pre><code>componentWillMount() {
    LocalStorageUtils.get('user');
  }
  </code></pre>
  
  <p><code>LocalStorageUtils</code> reads the value and brings it into Flux via <code>ServerAction</code> similar to the <a href="https://github.com/facebook/flux/blob/master/examples/flux-chat/js/utils/ChatWebAPIUtils.js#L51" rel="nofollow">flux chat example</a>.</p>
  
  <pre><code>get(key) {
    var value = window.localStorage.getItem(key);
    if (value) { 
      ServerActionCreators.receiveFromLocalStorage(key, value); 
    }
  }
  </code></pre>
  
  <p>That puts the user into my <code>UserStore</code> and into my views where I can show the username and some logout link, etc.</p>
  
  <p>I also have <code>ApiUtils.js</code> for requesting data from the server. So the question is: Where do I tell my <code>ApiUtils</code> that I have a logged-in user at initial page load?</p>
  
  <p>I could call some method inside <code>ApiUtils</code> from my <code>LocalStorageUtils</code> but that does not feel right.
  Or do I have to make another round trip whenever I get a change event inside my container component?</p>