angularfire:waitforAuth和requireAuth之间的差 [英] angularfire: the difference between waitforAuth and requireAuth

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

问题描述

于是我使用 requireAuth()火力用于开发web应用程序 gulpJs angularJs 火力地堡原因。我很新的三件事情。 requireAuth()方法在我的应用程序的伟大工程,在网上搜索了东西,我碰到 $ waitForAuth()我来仍然想不通的差异。从名字,一会等认证方式,但 requireAuth()(显然也等待吧?)。当它是理想的使用 $ waitForAuth(),当它是理想的使用 requireAuth()

  myApp.factory(身份认证,函数($火力点,$ firebaseObject,$ firebaseAuth,$ routeParams,$位置,FIREBASE_URL){//因为在这种情况下,不需要它们不张贴code的其它部件
VAR REF =新的火力地堡(FIREBASE_URL);
VAR AUTH = $ firebaseAuth(REF);
VAR mytempObj = {
   requireAuth:功能(){
        返回AUTH $ requireAuth()。
   },
   waitAuth:功能(){
        返回AUTH $ waitForAuth()。
   } //等待用户进行身份验证
}
返回mytempObj;}


解决方案

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆