2

所以我使用requireAuth()fromfirebase来开发一个使用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;

}
4

1 回答 1

5

$waitForAuth()将等待 promise 解决,并且不需要用户实际登录。这在您想要检查用户是否登录时很有用,然后做相应的事情。

$requireAuth()要求用户登录,否则承诺将被拒绝。对于保护用户需要登录的路线很有用。

于 2015-07-05T11:19:07.777 回答