title: AngularJs SPA logout
body: <p>I have posted more complex question here <a href="https://stackoverflow.com/questions/35920976/angularjs-logout-action">AngularJs logout action</a> . But I have another aspect to see, and I think that it should be separated question. </p>
  
  <p>I have Angualr SPA with authentication. Authentication implemented with bearer JWT tokens. I use <code>ng-route</code> to make different views. Let us imagine, that one view (using <code>/protected</code> route ,<code>protecetedController</code> and <code>protectedDataService</code>) contains protected resources, and another view (using <code>/unprotected</code> route, <code>unprotecetedController</code> and <code>unprotectedDataService</code>) contains unprotected resources. Controllers sample code : </p>
  
  <pre><code>(function () {
      'use strict';
  
      angular
          .module('protectedCtrl',[])
          .controller('protectedController', ['$location','protectedDataService', function ($location, protectedDataService) {
              var vm = this;
              vm.title = 'protectedController';
              protectedDataService.getData().then(function (res) {
                  vm.values = res.data;
              }, function (err) {
                  console.log(err);
              });
          }]);
  })();
  </code></pre>
  
  <p>Unprotected controller:</p>
  
  <pre><code>(function () {
      'use strict';
  
      angular
          .module('unprotectedCtrl',[])
          .controller('unprotectedController', ['$location','unprotectedDataService', function ($location, unprotectedDataService) {
              var vm = this;
              vm.title = 'unprotectedController';
              unprotectedDataService.getData().then(function (res) {
                  vm.values = res.data;
              }, function (err) {
                  console.log(err);
              });
          }]);
  })();
  </code></pre>
  
  <p>If unlogined user goes to protected resource (<code>/protected</code> path) he will be redirected to login page. But let us imagine, that logined user press logout button (for now I simply delete from browser local strage my token info and reload page). If user is on <code>/protected</code> page, he should be redirected to login page. If he is on <code>/unprotected</code> page nothing should happen. How can I implement this? How can I determine which page is active in <code>ng-view</code> (needs auth or does not) and make decision about redirection? </p>