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

Commit 40bfbbc

Browse files
committed
Merge pull request #748 from firebase/jw-fix-firebaseAuth-promises
Fixed issue with $firebaseAuth methods not resolving
2 parents 5463a63 + afd93e6 commit 40bfbbc

File tree

4 files changed

+164
-213
lines changed

4 files changed

+164
-213
lines changed

src/FirebaseAuth.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
7777
*/
7878
signInWithCustomToken: function(authToken) {
79-
return this._utils.Q(this._auth.signInWithCustomToken(authToken).then);
79+
return this._utils.promise.when(this._auth.signInWithCustomToken(authToken));
8080
},
8181

8282
/**
@@ -85,7 +85,7 @@
8585
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
8686
*/
8787
signInAnonymously: function() {
88-
return this._utils.Q(this._auth.signInAnonymously().then);
88+
return this._utils.promise.when(this._auth.signInAnonymously());
8989
},
9090

9191
/**
@@ -96,7 +96,7 @@
9696
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
9797
*/
9898
signInWithEmailAndPassword: function(email, password) {
99-
return this._utils.Q(this._auth.signInWithEmailAndPassword(email, password).then);
99+
return this._utils.promise.when(this._auth.signInWithEmailAndPassword(email, password));
100100
},
101101

102102
/**
@@ -106,7 +106,7 @@
106106
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
107107
*/
108108
signInWithPopup: function(provider) {
109-
return this._utils.Q(this._auth.signInWithPopup(this._getProvider(provider)).then);
109+
return this._utils.promise.when(this._auth.signInWithPopup(this._getProvider(provider)));
110110
},
111111

112112
/**
@@ -116,7 +116,7 @@
116116
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
117117
*/
118118
signInWithRedirect: function(provider) {
119-
return this._utils.Q(this._auth.signInWithRedirect(this._getProvider(provider)).then);
119+
return this._utils.promise.when(this._auth.signInWithRedirect(this._getProvider(provider)));
120120
},
121121

122122
/**
@@ -126,7 +126,7 @@
126126
* @return {Promise<Object>} A promise fulfilled with an object containing authentication data.
127127
*/
128128
signInWithCredential: function(credential) {
129-
return this._utils.Q(this._auth.signInWithCredential(credential).then);
129+
return this._utils.promise.when(this._auth.signInWithCredential(credential));
130130
},
131131

132132
/**
@@ -181,7 +181,7 @@
181181
* rejected if the client is unauthenticated and rejectIfAuthDataIsNull is true.
182182
*/
183183
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
184-
var utils = this._utils, self = this;
184+
var self = this;
185185

186186
// wait for the initial auth state to resolve; on page load we have to request auth state
187187
// asynchronously so we don't want to resolve router methods or flash the wrong state
@@ -191,10 +191,10 @@
191191
// to the current auth state and not a stale/initial state
192192
var authData = self.getAuth(), res = null;
193193
if (rejectIfAuthDataIsNull && authData === null) {
194-
res = utils.reject("AUTH_REQUIRED");
194+
res = self._utils.reject("AUTH_REQUIRED");
195195
}
196196
else {
197-
res = utils.resolve(authData);
197+
res = self._utils.resolve(authData);
198198
}
199199
return res;
200200
});
@@ -274,7 +274,7 @@
274274
* uid of the created user.
275275
*/
276276
createUserWithEmailAndPassword: function(email, password) {
277-
return this._utils.Q(this._auth.createUserWithEmailAndPassword(email, password).then);
277+
return this._utils.promise.when(this._auth.createUserWithEmailAndPassword(email, password));
278278
},
279279

280280
/**
@@ -286,7 +286,7 @@
286286
updatePassword: function(password) {
287287
var user = this.getAuth();
288288
if (user) {
289-
return this._utils.Q(user.updatePassword(password).then);
289+
return this._utils.promise.when(user.updatePassword(password));
290290
} else {
291291
return this._utils.reject("Cannot update password since there is no logged in user.");
292292
}
@@ -301,7 +301,7 @@
301301
updateEmail: function(email) {
302302
var user = this.getAuth();
303303
if (user) {
304-
return this._utils.Q(user.updateEmail(email).then);
304+
return this._utils.promise.when(user.updateEmail(email));
305305
} else {
306306
return this._utils.reject("Cannot update email since there is no logged in user.");
307307
}
@@ -315,7 +315,7 @@
315315
deleteUser: function() {
316316
var user = this.getAuth();
317317
if (user) {
318-
return this._utils.Q(user.delete().then);
318+
return this._utils.promise.when(user.delete());
319319
} else {
320320
return this._utils.reject("Cannot delete user since there is no logged in user.");
321321
}
@@ -329,7 +329,7 @@
329329
* @return {Promise<>} An empty promise fulfilled once the reset password email is sent.
330330
*/
331331
sendPasswordResetEmail: function(email) {
332-
return this._utils.Q(this._auth.sendPasswordResetEmail(email).then);
332+
return this._utils.promise.when(this._auth.sendPasswordResetEmail(email));
333333
}
334334
};
335335
})();

src/utils.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,7 @@
2525

2626
.factory('$firebaseUtils', ["$q", "$timeout", "$rootScope",
2727
function($q, $timeout, $rootScope) {
28-
29-
// ES6 style promises polyfill for angular 1.2.x
30-
// Copied from angular 1.3.x implementation: https://github.com/angular/angular.js/blob/v1.3.5/src/ng/q.js#L539
31-
function Q(resolver) {
32-
if (!angular.isFunction(resolver)) {
33-
throw new Error('missing resolver function');
34-
}
35-
36-
var deferred = $q.defer();
37-
38-
function resolveFn(value) {
39-
deferred.resolve(value);
40-
}
41-
42-
function rejectFn(reason) {
43-
deferred.reject(reason);
44-
}
45-
46-
resolver(resolveFn, rejectFn);
47-
48-
return deferred.promise;
49-
}
50-
5128
var utils = {
52-
Q: Q,
5329
/**
5430
* Returns a function which, each time it is invoked, will gather up the values until
5531
* the next "tick" in the Angular compiler process. Then they are all run at the same
@@ -183,8 +159,7 @@
183159

184160
resolve: $q.when,
185161

186-
//TODO: Remove false branch and use only angular implementation when we drop angular 1.2.x support.
187-
promise: angular.isFunction($q) ? $q : Q,
162+
promise: $q,
188163

189164
makeNodeResolver:function(deferred){
190165
return function(err,result){

0 commit comments

Comments
 (0)