|
4 | 4 |
|
5 | 5 | // Define a service which provides user authentication and management. |
6 | 6 | angular.module('firebase').factory('$firebaseAuth', [ |
7 | | - '$firebaseUtils', function($firebaseUtils) { |
| 7 | + '$q', '$firebaseUtils', function($q, $firebaseUtils) { |
8 | 8 | /** |
9 | 9 | * This factory returns an object allowing you to manage the client's authentication state. |
10 | 10 | * |
|
15 | 15 | return function(auth) { |
16 | 16 | auth = auth || firebase.auth(); |
17 | 17 |
|
18 | | - var firebaseAuth = new FirebaseAuth($firebaseUtils, auth); |
| 18 | + var firebaseAuth = new FirebaseAuth($q, $firebaseUtils, auth); |
19 | 19 | return firebaseAuth.construct(); |
20 | 20 | }; |
21 | 21 | } |
22 | 22 | ]); |
23 | 23 |
|
24 | | - FirebaseAuth = function($firebaseUtils, auth) { |
| 24 | + FirebaseAuth = function($q, $firebaseUtils, auth) { |
| 25 | + this._q = $q; |
25 | 26 | this._utils = $firebaseUtils; |
26 | 27 | if (typeof ref === 'string') { |
27 | 28 | throw new Error('Please provide a Firebase reference instead of a URL when creating a `$firebaseAuth` object.'); |
|
76 | 77 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
77 | 78 | */ |
78 | 79 | signInWithCustomToken: function(authToken) { |
79 | | - return this._utils.promise.when(this._auth.signInWithCustomToken(authToken)); |
| 80 | + return this._q.when(this._auth.signInWithCustomToken(authToken)); |
80 | 81 | }, |
81 | 82 |
|
82 | 83 | /** |
|
85 | 86 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
86 | 87 | */ |
87 | 88 | signInAnonymously: function() { |
88 | | - return this._utils.promise.when(this._auth.signInAnonymously()); |
| 89 | + return this._q.when(this._auth.signInAnonymously()); |
89 | 90 | }, |
90 | 91 |
|
91 | 92 | /** |
|
96 | 97 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
97 | 98 | */ |
98 | 99 | signInWithEmailAndPassword: function(email, password) { |
99 | | - return this._utils.promise.when(this._auth.signInWithEmailAndPassword(email, password)); |
| 100 | + return this._q.when(this._auth.signInWithEmailAndPassword(email, password)); |
100 | 101 | }, |
101 | 102 |
|
102 | 103 | /** |
|
106 | 107 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
107 | 108 | */ |
108 | 109 | signInWithPopup: function(provider) { |
109 | | - return this._utils.promise.when(this._auth.signInWithPopup(this._getProvider(provider))); |
| 110 | + return this._q.when(this._auth.signInWithPopup(this._getProvider(provider))); |
110 | 111 | }, |
111 | 112 |
|
112 | 113 | /** |
|
116 | 117 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
117 | 118 | */ |
118 | 119 | signInWithRedirect: function(provider) { |
119 | | - return this._utils.promise.when(this._auth.signInWithRedirect(this._getProvider(provider))); |
| 120 | + return this._q.when(this._auth.signInWithRedirect(this._getProvider(provider))); |
120 | 121 | }, |
121 | 122 |
|
122 | 123 | /** |
|
126 | 127 | * @return {Promise<Object>} A promise fulfilled with an object containing authentication data. |
127 | 128 | */ |
128 | 129 | signInWithCredential: function(credential) { |
129 | | - return this._utils.promise.when(this._auth.signInWithCredential(credential)); |
| 130 | + return this._q.when(this._auth.signInWithCredential(credential)); |
130 | 131 | }, |
131 | 132 |
|
132 | 133 | /** |
|
191 | 192 | // to the current auth state and not a stale/initial state |
192 | 193 | var authData = self.getAuth(), res = null; |
193 | 194 | if (rejectIfAuthDataIsNull && authData === null) { |
194 | | - res = self._utils.reject("AUTH_REQUIRED"); |
| 195 | + res = self._q.reject("AUTH_REQUIRED"); |
195 | 196 | } |
196 | 197 | else { |
197 | | - res = self._utils.resolve(authData); |
| 198 | + res = self._q.when(authData); |
198 | 199 | } |
199 | 200 | return res; |
200 | 201 | }); |
|
226 | 227 | _initAuthResolver: function() { |
227 | 228 | var auth = this._auth; |
228 | 229 |
|
229 | | - return this._utils.promise(function(resolve) { |
| 230 | + return this._q(function(resolve) { |
230 | 231 | var off; |
231 | 232 | function callback() { |
232 | 233 | // Turn off this onAuthStateChanged() callback since we just needed to get the authentication data once. |
|
274 | 275 | * uid of the created user. |
275 | 276 | */ |
276 | 277 | createUserWithEmailAndPassword: function(email, password) { |
277 | | - return this._utils.promise.when(this._auth.createUserWithEmailAndPassword(email, password)); |
| 278 | + return this._q.when(this._auth.createUserWithEmailAndPassword(email, password)); |
278 | 279 | }, |
279 | 280 |
|
280 | 281 | /** |
|
286 | 287 | updatePassword: function(password) { |
287 | 288 | var user = this.getAuth(); |
288 | 289 | if (user) { |
289 | | - return this._utils.promise.when(user.updatePassword(password)); |
| 290 | + return this._q.when(user.updatePassword(password)); |
290 | 291 | } else { |
291 | | - return this._utils.reject("Cannot update password since there is no logged in user."); |
| 292 | + return this._q.reject("Cannot update password since there is no logged in user."); |
292 | 293 | } |
293 | 294 | }, |
294 | 295 |
|
|
301 | 302 | updateEmail: function(email) { |
302 | 303 | var user = this.getAuth(); |
303 | 304 | if (user) { |
304 | | - return this._utils.promise.when(user.updateEmail(email)); |
| 305 | + return this._q.when(user.updateEmail(email)); |
305 | 306 | } else { |
306 | | - return this._utils.reject("Cannot update email since there is no logged in user."); |
| 307 | + return this._q.reject("Cannot update email since there is no logged in user."); |
307 | 308 | } |
308 | 309 | }, |
309 | 310 |
|
|
315 | 316 | deleteUser: function() { |
316 | 317 | var user = this.getAuth(); |
317 | 318 | if (user) { |
318 | | - return this._utils.promise.when(user.delete()); |
| 319 | + return this._q.when(user.delete()); |
319 | 320 | } else { |
320 | | - return this._utils.reject("Cannot delete user since there is no logged in user."); |
| 321 | + return this._q.reject("Cannot delete user since there is no logged in user."); |
321 | 322 | } |
322 | 323 | }, |
323 | 324 |
|
|
329 | 330 | * @return {Promise<>} An empty promise fulfilled once the reset password email is sent. |
330 | 331 | */ |
331 | 332 | sendPasswordResetEmail: function(email) { |
332 | | - return this._utils.promise.when(this._auth.sendPasswordResetEmail(email)); |
| 333 | + return this._q.when(this._auth.sendPasswordResetEmail(email)); |
333 | 334 | } |
334 | 335 | }; |
335 | 336 | })(); |
0 commit comments