Skip to content

Commit

Permalink
Merge pull request #473 from jamestalmage/offAuth-fix
Browse files Browse the repository at this point in the history
call offAuth() with correct method.
  • Loading branch information
Jacob Wenger committed Nov 20, 2014
2 parents 6ed1fc1 + 38eca0a commit 3544c81
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/FirebaseAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,38 @@
},

// Helper onAuth() callback method for the two router-related methods.
_routerMethodOnAuthCallback: function(deferred, rejectIfAuthDataIsNull, authData) {
if (authData !== null) {
deferred.resolve(authData);
} else if (rejectIfAuthDataIsNull) {
deferred.reject("AUTH_REQUIRED");
} else {
deferred.resolve(null);
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
var ref = this._ref;
var deferred = this._q.defer();

function callback(authData) {
if (authData !== null) {
deferred.resolve(authData);
} else if (rejectIfAuthDataIsNull) {
deferred.reject("AUTH_REQUIRED");
} else {
deferred.resolve(null);
}

// Turn off this onAuth() callback since we just needed to get the authentication data once.
ref.offAuth(callback);
}

// Turn off this onAuth() callback since we just needed to get the authentication data once.
this._ref.offAuth(this._routerMethodOnAuthCallback);
ref.onAuth(callback);

return deferred.promise;
},

// Returns a promise which is resolved if the client is authenticated and rejects otherwise.
// This can be used to require that a route has a logged in user.
requireAuth: function() {
var deferred = this._q.defer();

this._ref.onAuth(this._routerMethodOnAuthCallback.bind(this, deferred, /* rejectIfAuthDataIsNull */ true));

return deferred.promise;
return this._routerMethodOnAuthPromise(true);
},

// Returns a promise which is resolved with the client's current authenticated data. This can
// be used in a route's resolve() method to grab the current authentication data.
waitForAuth: function() {
var deferred = this._q.defer();

this._ref.onAuth(this._routerMethodOnAuthCallback.bind(this, deferred, /* rejectIfAuthDataIsNull */ false));

return deferred.promise;
return this._routerMethodOnAuthPromise(false);
},


Expand Down

0 comments on commit 3544c81

Please sign in to comment.