2016-06-15 11 views
1

AngularJsを初めて使用していますが、認証が正しく処理されるかどうかはわかりません。
$firebaseAuth()は、アプリを更新しても認証ステータスが維持されると思います。しかし、私がアプリをリフレッシュするたびに、$firebaseAuth()はユーザーを再認証せず、再ログインする必要があります。
ドキュメントを読み、ソースコードを検索しましたが、セッションの永続性を構成できる機能が見つかりませんでした。 2つのパラメータemailpasswordのみが受け入れられます。Angularfire Authセッションの永続性

バージョン:
angularjs v1.4.10
angularfire v2.0.1の
firebase v3.0.3

authenticationService litcoffeeスクリプト

app.factory "authenticationService", [ 
    "$firebaseAuth" 
    "$location" 
    "$rootScope" 
    ($firebaseAuth, $location, $rootScope) -> 
     login: (email, password, redirectUrl = "/") -> 
      $rootScope.authObj.$signInWithEmailAndPassword(email, password) 
      .then(
       (firebaseUser) -> 
        console.log firebaseUser 
        $rootScope.firebaseUser = firebaseUser 
        return true 

       (error) -> 
        $rootScope.firebaseUser = null 
        console.log error 
        alert error.message 
        return false 
      ) 

     logout: (redirectUrl = "/login") -> 
      $rootScope.authObj.$signOut() 
      $location.path redirectUrl 

     isLogged:() -> 
      if $rootScope.authObj.$getAuth() 
       return true 
      else  
       return false 

] 

私はその意志コントローラ上のユーザ認証のステータスを確認authenticationService.isLogged()に電話すると、ユーザーがログに記録されていない場合はログインページにリダイレクトされます。
私が達成したいのは、単純な認証だけです。ユーザーは、更新しても認証ステータスを維持します。
私が間違った方向にいる場合は私を修正してください。どんな助けでも大歓迎です。

答えて

2

実際には私のせいです。 FirebaseとAngularFireは、デフォルトで認証セッションの永続性を維持します。 私が間違っていたのは、ページがロードされた直後に認証ステータスをチェックすることでした。 AngularFireがまだ起動していない瞬間、アプリケーションの再認証には時間がかかるでしょう。

したがって、$firebaseAuth.$onAuthStateChangedは非常に役に立ちます。 あなたのページが読み込まれたらそれを聞いてください。イベントが発生すると、ユーザーが認証されたかどうかが通知されます。

+0

男、U'r人形のマスター!残念ながら、ドキュメントには、['$ onAuth(コールバック[、コンテキスト])'](https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication-onauthcallback-コンテキスト)これの代わりに '$ onAuthStateChanged'が' $ firebaseAuth() 'のキーにあります。 – oshliaer