Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 3544c81

Browse files
author
Jacob Wenger
committed
Merge pull request #473 from jamestalmage/offAuth-fix
call offAuth() with correct method.
2 parents 6ed1fc1 + 38eca0a commit 3544c81

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/FirebaseAuth.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,37 +155,38 @@
155155
},
156156

157157
// Helper onAuth() callback method for the two router-related methods.
158-
_routerMethodOnAuthCallback: function(deferred, rejectIfAuthDataIsNull, authData) {
159-
if (authData !== null) {
160-
deferred.resolve(authData);
161-
} else if (rejectIfAuthDataIsNull) {
162-
deferred.reject("AUTH_REQUIRED");
163-
} else {
164-
deferred.resolve(null);
158+
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
159+
var ref = this._ref;
160+
var deferred = this._q.defer();
161+
162+
function callback(authData) {
163+
if (authData !== null) {
164+
deferred.resolve(authData);
165+
} else if (rejectIfAuthDataIsNull) {
166+
deferred.reject("AUTH_REQUIRED");
167+
} else {
168+
deferred.resolve(null);
169+
}
170+
171+
// Turn off this onAuth() callback since we just needed to get the authentication data once.
172+
ref.offAuth(callback);
165173
}
166174

167-
// Turn off this onAuth() callback since we just needed to get the authentication data once.
168-
this._ref.offAuth(this._routerMethodOnAuthCallback);
175+
ref.onAuth(callback);
176+
177+
return deferred.promise;
169178
},
170179

171180
// Returns a promise which is resolved if the client is authenticated and rejects otherwise.
172181
// This can be used to require that a route has a logged in user.
173182
requireAuth: function() {
174-
var deferred = this._q.defer();
175-
176-
this._ref.onAuth(this._routerMethodOnAuthCallback.bind(this, deferred, /* rejectIfAuthDataIsNull */ true));
177-
178-
return deferred.promise;
183+
return this._routerMethodOnAuthPromise(true);
179184
},
180185

181186
// Returns a promise which is resolved with the client's current authenticated data. This can
182187
// be used in a route's resolve() method to grab the current authentication data.
183188
waitForAuth: function() {
184-
var deferred = this._q.defer();
185-
186-
this._ref.onAuth(this._routerMethodOnAuthCallback.bind(this, deferred, /* rejectIfAuthDataIsNull */ false));
187-
188-
return deferred.promise;
189+
return this._routerMethodOnAuthPromise(false);
189190
},
190191

191192

0 commit comments

Comments
 (0)