title: delay stateChangeStart until it finishes an ajax
body: <p>I'm trying to check on state changes whether user is logged and I'm trying to restore the logged state with a token from the cookies when he is not</p>
  
  <pre><code>eFx.run(function($rootScope, $cookieStore, $location, Auth) {
    $rootScope.$on('$stateChangeStart', function(event) {
      if ($rootScope.user == null) {
        if ($cookieStore.get('token') != undefined) {
          Auth.logIn({'token': $cookieStore.get('token')}).then(function(data) {
            $cookieStore.put('token', data.token);
            $rootScope.user = data.user;
            $rootScope.token = data.token;
          }, function(data) {
            $location.path("/login");
          });
        }
        else {
          $location.path("/login");
        }
      }
    });
  });
  </code></pre>
  
  <p>The problem that I'm having is my page controller gets initiated and calls an ajax with a token that is trying to get from the <code>$rootScope</code> before this Auth ajax inside the stateChangeStart returns the promise.</p>
  
  <p>Is there a way to make this block of code so it loads the page only after it returned the ajax promise?
  Thank you in advance, Daniel.</p>