2016-10-03 3 views
1

Firebase V3、AngularJS、ui.routerを使用して、私のサイトのさまざまなルートを保護したい。Firebase v3で角度ルートを確保する方法は?

Thisは同様の問題のようです。私はSOの投稿の手順を踏んだが、私のために働いていない。私が起こることを期待何

をログアウトし、ログインしたときにFAQページを表示する必要がある場合、私は、ログインページに転送する必要がありますよくあるご質問リンクをクリックすると、実際に何が起こる

FAQページには全くアクセスできません。ログインしても差はありません。また、ログアウトするとログインページに転送されません。

私のrun機能でこのエラーが発生しています。

ReferenceError: Firebase is not defined(…)  

私は私がいない場合、私は、私は、依存配列からFirebaseを削除しても、モジュールのインジェクタエラーを取得し、ページ上のAngularFireを含めました。

var app = angular.module('app', ['ui.router', 'firebase']); 
app.constant('FirebaseDatabaseUrl', 'https://myfbdb.firebaseio.com'); 
app.config(function($stateProvider, $urlRouterProvider, $firebaseRefProvider, FirebaseDatabaseUrl) { 
    $firebaseRefProvider.registerUrl(FirebaseDatabaseUrl); 
// If a route other than status is requested, 
// go to the auth route 
//$urlRouterProvider.otherwise('/logintest/login'); 

$stateProvider 
    .state('login', { 
     url: '/login', 
     templateUrl: 'pages/login.html', 
     controller: 'LoginController as login' 
    }) 

    .state('faq', { 
     url: '/faq', 
     templateUrl: 'pages/faq.html', 
     controller: 'FaqController as faq', 
     resolve: { 
      // controller will not be loaded until $requireSignIn resolves 
      "firebaseUser": ["$firebaseAuthService", function($firebaseAuthService) { 
      console.log('waitForSignIn') 
        // $waitForSignIn returns a promise so the resolve waits for it to complete 
        return $firebaseAuthService.$waitForSignIn(); 
      }] 
      } 

    }) 
    .state('about', { 
     url: '/about', 
     templateUrl: 'pages/about.html', 
     controller: 'AboutController as about', 
     resolve: { 
      // controller will not be loaded until $requireSignIn resolves 
      "firebaseUser": ["$firebaseAuthService", function($firebaseAuthService) { 
      // If the promise is rejected, it will throw a $stateChangeError 
      return $firebaseAuthService.$requireSignIn(); 
      }] 
     }   
    }) 

}); 



app.controller('FaqController', ['$scope', 'firebaseUser', function($scope, firebaseUser){ 
console.log('faq') 
}]); 





app.run(["$rootScope", "$state", function($rootScope, $state) { 
    console.log('run'); 
    $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) { 
// We can catch the error thrown when the $requireSignIn promise is rejected 
// and redirect the user back to the home page 
if (error === "AUTH_REQUIRED") { 
    console.log('redirecting to login page') 
    $state.go("login"); 
} 
}); 
    }]); 
+0

AngulsrFireの古いバージョンを使用しているようです。あなたのバージョン番号は何ですか? –

+0

お返事ありがとうございます。私はv1.2.0を使用しています。 – user1532669

+0

それが問題になります。 2.02にアップグレード –

答えて

2

AngularFireバージョン2.0以降は、Firebase 3.0と互換性があります。 AngularFire 2.0以下のものは、Firebaseの旧バージョン用です。

関連する問題