angularfire: the difference between waitforAuth and requireAuth

Coding Enthusiast

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;

}
Chrillewoodz

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related