angularfire: the difference between waitforAuth and requireAuth

泪湿孤枕 提交于 2019-12-11 03:18:41

问题


So I am using requireAuth() from firebase to develop a web app using gulpJs, angularJs and Firebase of cause. I am quite new to the three things. requireAuth() method works great in my app, searching up stuff online, I came across $waitForAuth() and I still can't figure out the difference. From the name, one will wait for authentification but requireAuth() (will obviously also wait right?). When is it ideal to use the $waitForAuth() and when is it ideal to use 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;

}

回答1:


$waitForAuth() will wait for the promise to resolve, and will not require the user to actually be logged in. This makes it useful when you want to check if the user is logged in or not, and then do something accordingly.

$requireAuth() will require the user to be logged in or the promise will be rejected. Useful for securing routes where the user needs to be logged in.



来源:https://stackoverflow.com/questions/31227142/angularfire-the-difference-between-waitforauth-and-requireauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!