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

Commit 4298feb

Browse files
committed
call offAuth() with correct method.
closes #471.
1 parent 6ed1fc1 commit 4298feb

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/FirebaseAuth.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,37 +155,35 @@
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);
165-
}
158+
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
159+
var ref = this._ref,
160+
deferred = this._q.defer();
161+
162+
var callback = function (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+
// Turn off this onAuth() callback since we just needed to get the authentication data once.
171+
ref.offAuth(callback);
172+
};
166173

167-
// Turn off this onAuth() callback since we just needed to get the authentication data once.
168-
this._ref.offAuth(this._routerMethodOnAuthCallback);
174+
return deferred.promise;
169175
},
170176

171177
// Returns a promise which is resolved if the client is authenticated and rejects otherwise.
172178
// This can be used to require that a route has a logged in user.
173179
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;
180+
return this._routerMethodOnAuthPromise(true);
179181
},
180182

181183
// Returns a promise which is resolved with the client's current authenticated data. This can
182184
// be used in a route's resolve() method to grab the current authentication data.
183185
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;
186+
return this._routerMethodOnAuthPromise(false);
189187
},
190188

191189

0 commit comments

Comments
 (0)