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