本文介绍了angularfire:waitforAuth 和 requireAuth 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 firebase 中的 requireAuth() 来使用 gulpJsangularJsFirebase 原因.我对这三件事很陌生.requireAuth() 方法在我的应用中效果很好,在网上搜索东西,我遇到了 $waitForAuth() ,但我仍然无法弄清楚其中的区别.从名字上看,一个人会等待认证,但 requireAuth() (显然也会等待吧?).什么时候使用 $waitForAuth() 比较理想,什么时候使用 requireAuth() 比较理想.

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;

}

推荐答案

$waitForAuth() 将等待 promise 解决,并且不需要用户实际登录.这使得当您想检查用户是否已登录,然后执行相应操作时,它很有用.

$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()要求用户登录,否则承诺将被拒绝.用于保护用户需要登录的路由.

$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.

这篇关于angularfire:waitforAuth 和 requireAuth 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 05:58