1

我试图将所有未授权流量路由到登录页面,并且正在使用angularfire进行身份验证。 Here's all the relevant code.我知道大部分都是坏的,但我想首先得到它。有问题的代码是:

App.js

app.run(['$rootScope', '$location', 'AuthenticatorService', function ($rootScope, $location, AuthenticatorService) { 
     $rootScope.$on('$routeChangeStart', function (event) { 

      if (AuthenticatorService.isLoggedIn) { 
       console.log('DENY'); 
       event.preventDefault(); 
       $location.path('/login'); 
      } 
      else { 
       console.log('ALLOW'); 
       $location.path('/home'); 
      } 
     }); 
    }]); 

回答

4

你已经错过了两件事情在你的代码

  1. ng-app应该是ng-app="BillingApp",而不是ng-app="App"
  2. 你缺少$rootScope参考在服务DI阵列中。

代码

auth.service('AuthenticatorService', [ '$firebaseAuth', '$rootScope',//<--added this 
    function($firebaseAuth,$rootScope) { 

Plunkr Here