title: ngCookies returns undefined for existing cookie
body: <p>I've been scratching my head for this one for hours now yet still haven't found the cause or solution.</p>
  
  <p>Basically I have an Angular.js frontend that tries to log users in (with <code>ngCookies</code> on Angular.js 1.3.15) by communicating with an authentication API endpoint in the backend. Upon success, my code should redirect the user to another page.</p>
  
  <p>So the login code looks something like:</p>
  
  <pre><code>auth.login($scope.user).success(function() {
    $state.go('overview');
  });
  </code></pre>
  
  <p>where <code>auth</code> is a service that has a <code>login</code> method which simply sends an POST request to the backend. <code>$state.go('overview')</code> will do the redirect. This code should be ok as I get HTTP200 back from the server given I supply the correct user credentials. However, the browser won't redirect me to the overview page because it still thinks I'm not logged in unless I refresh the page.</p>
  
  <p>The code that checks if the current user is logged in uses a helper method called <code>getToken()</code>, where I use <code>ngCookies</code> to retrieve a cookie named <code>USER_SESSION</code>. And this method is where I think the problem is.</p>
  
  <p>The method itself is simply</p>
  
  <pre><code>auth.getToken = function() {
    return $cookies.USER_SESSION;
  };
  </code></pre>
  
  <p>However it always returns <code>undefined</code> even when the <code>USER_SESSION</code> cookie exists in the browser.</p>
  
  <p>Some testing I did (on a remote testing server so accessing cookies in <code>localhost</code> shouldn't be a concern):</p>
  
  <pre><code>auth.getToken = function() {
    console.log($cookies);
    console.log($cookies.USER_SESSION);
    return $cookies.USER_SESSION;
  }
  </code></pre>
  
  <p>The results of <code>console.log</code>:</p>
  
  <pre><code>// Before login:
  Object {...} // No USER_SESSION, this is good
  undefined
  
  // After hitting the login button, browser sends AJAX request,
  // server returns HTTP200 response with Set-Cookie in the header:
  Object {USER_SESSION: ""aa21fcd..."", ...} // UESR_SESSION exists, good
  undefined // ???
  
  // After refreshing the page:
  Object {USER_SESSION: ""09b4tk..."", ...}
  "09b4tk..."
  </code></pre>
  
  <p>Are the double quotes the problem here? I thought so initially, but after refreshing the page, <code>$cookies</code> returns the same thing (same double quotes but a different <code>USER_SESSION</code> value) and <code>$cookies.USER_SESSION</code> would have the correct value, and user would be on the overview page.</p>
  
  <p>Does this mean <code>Set-Cookie</code> in the HTTP response header needs a page refresh to take effect?</p>
  
  <p>Thanks!</p>
  
  <p>P.S. Same problem occurs with <code>cookieStore</code>.</p>