title: AngularJs - best way to limit access to 'logged in' users
body: <p>I'm struggling with setting up a login system for an app i'm creating.</p>
  
  <p>I'm able to set cookies for when the user is logged in or out. I don't think that testing every view if the user is logged in is a very elegant solution, and i'm afraid a page here and there may fall through the cracks (it's a rather large app).</p>
  
  <p>I'm thinking the best way would be to intercept route changes somehow and check if the user is logged in, otherwise send them to a login/create user page. I've found a few methods, but nothing seems to be officially documented. Has anyone used this type of method in a real world case, and was it effective?</p>
  
  <p>My route file looks like this:</p>
  
  <pre><code>'use strict';
  
  app.config(['$routeProvider', function ($routeProvider) {
      $routeProvider
          // LOGIN
          .when('/User/LoginUser', {templateUrl: 'views/user/login.html',controller: 'loginCtrl'})
  
      ....... more routes here.......
  
          // DEFAULT
          .otherwise({redirectTo: '/'});
  }]);
  </code></pre>
  
  <p>Any help or suggestions, or points to documented real world examples of how I would do something like this would be greatly appreciated!</p>