angularfire:waitforAuth和requireAuth之间的区别

Cod*_*ast 2 angularjs firebase angularfire firebase-authentication

所以我用requireAuth()firebase使用开发一个Web应用程序gulpJs,angularJsFirebase的原因.我对这三件事情都很陌生.requireAuth()方法在我的应用程序中运行良好,在线搜索内容,我遇到了$waitForAuth(),我仍然无法弄清楚差异.从名字中,人们会等待认证但是requireAuth()(显然也会等待吗?).什么时候使用它是理想的$waitForAuth(),什么时候使用它是理想的requireAuth().

myApp.factory('Authentification', function($firebase, $firebaseObject, $firebaseAuth, $routeParams, $location, FIREBASE_URL){ 

//not posting the other parts of the code since they are not needed in this case
var ref = new Firebase(FIREBASE_URL);
var auth = $firebaseAuth(ref);
var mytempObj = {
   requireAuth: function() {
        return auth.$requireAuth();
   },
   waitAuth: function(){
        return auth.$waitForAuth();
   }//wait for user to be authenticated
}
return mytempObj;

}
Run Code Online (Sandbox Code Playgroud)

Chr*_*odz 5

$waitForAuth() 将等待承诺解决,并且不会要求用户实际登录.这使得当您想要检查用户是否已登录时它非常有用,然后相应地执行某些操作.

$requireAuth()要求用户登录或承诺将被拒绝.用于保护用户需要登录的路由.