Authentication firebase身份验证令牌的存储

Authentication firebase身份验证令牌的存储,authentication,angularjs,token,firebase,angularfire,Authentication,Angularjs,Token,Firebase,Angularfire,我有一个Firebase AngularJS应用程序,我正在使用FirebaseSimpleLogin执行身份验证,但我在理解如何在我的应用程序中持久化登录用户时遇到了一些问题。每次我登录并刷新页面时,似乎我不再经过身份验证。我知道登录后会生成一个令牌,用于对用户进行身份验证,但我是否需要在每个页面上使用该令牌对他们进行身份验证?如果需要,是否会在我的应用程序和firebase之间产生任何类型的开销 我的应用程序中执行登录/身份验证的部分 var ref = new Firebase("http

我有一个Firebase AngularJS应用程序,我正在使用
FirebaseSimpleLogin
执行身份验证,但我在理解如何在我的应用程序中持久化登录用户时遇到了一些问题。每次我登录并刷新页面时,似乎我不再经过身份验证。我知道登录后会生成一个令牌,用于对用户进行身份验证,但我是否需要在每个页面上使用该令牌对他们进行身份验证?如果需要,是否会在我的应用程序和firebase之间产生任何类型的开销

我的应用程序中执行登录/身份验证的部分

var ref = new Firebase("https://xxx.firebaseio.com/");
angularFireAuth.initialize(ref, {scope: $scope, name: "user", path:"/login"});

    // Used to authenticate user at a later time
$scope.auth = function(token, callback)
{

    ref.auth(token, function(error, data) {

        if(error) 
        {
            console.log("Login Failed!", error);
        } 
        else 
        {
            $scope.$apply(function()
            {
                $scope.user = data.auth;
            }); 
        }

        if (typeof callback === 'function')
        {
            callback(error,data);
        }

    });
};


    // Login to fetch authentication token to be used by $scope.auth()
$scope.login = function()
{   
    angularFireAuth.login("password", { 
        email: $scope.credentials.email,
        password: $scope.credentials.password
    });
};


    // On login stores user within $scope
$scope.$on("angularFireAuth:login", function(evt, user) {
    $scope.$apply(function()
    {
                 // Is it possible to save this user accross my application not just in this $scope
             $scope.user = user; 

    });
});
以下是捕获电子邮件/密码组合的标记

<div class="container-single" center>
               <h3>Sign in</h3>
               <input type="text" ng-model="credentials.email" placeholder="Username" />
               <input type="password" ng-model="credentials.password" placeholder="Password" />
               <input type="checkbox" id="checkbox-1" name="checkbox-1" /> <label>Remember my password</label>
               <button ng-click="login()">Sign in</button>
           </div>

登录
记住我的密码
登录

如果您使用的是
angularFireAuth
,那么您不需要自己进行任何身份验证。只需检查
$scope.user
值,查看用户是否在每个视图中都已登录

var ref=新Firebase(“https://xxx.firebaseio.com/");
初始化(ref,{scope:$scope,名称:“user”,路径:“/login”});
$scope.login=function(){
angularFireAuth.login(“密码”{
电子邮件:$scope.credentials.email,
密码:$scope.credentials.password
});
};

成功登录后,
$scope.user
将自动设置为用户详细信息。

非常感谢,我添加到$scope的身份验证功能没有必要。