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

Commit ea4c7be

Browse files
author
Jacob Wenger
committed
Wrapped authentication methods in try/catch blocks to handle invalid input errors
1 parent 9939a37 commit ea4c7be

File tree

1 file changed

+63
-18
lines changed

1 file changed

+63
-18
lines changed

src/FirebaseAuth.js

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Define a service which provides user authentication and management.
66
angular.module('firebase').factory('$firebaseAuth', [
77
'$q', '$firebaseUtils', '$log', function($q, $firebaseUtils, $log) {
8-
// This factory returns an object containing the current authentication state of the client.
9-
// This service takes one argument:
10-
//
11-
// * `ref`: A Firebase reference.
12-
//
13-
// The returned object contains methods for authenticating clients, retrieving authentication
14-
// state, and managing users.
8+
/**
9+
* This factory returns an object allowing you to manage the client's authentication state.
10+
*
11+
* @param {Firebase} ref A Firebase reference to authenticate.
12+
* @return {object} An object containing methods for authenticating clients, retrieving
13+
* authentication state, and managing users.
14+
*/
1515
return function(ref) {
1616
var auth = new FirebaseAuth($q, $firebaseUtils, $log, ref);
1717
return auth.construct();
@@ -77,7 +77,11 @@
7777
authWithCustomToken: function(authToken, options) {
7878
var deferred = this._q.defer();
7979

80-
this._ref.authWithCustomToken(authToken, this._utils.makeNodeResolver(deferred), options);
80+
try {
81+
this._ref.authWithCustomToken(authToken, this._utils.makeNodeResolver(deferred), options);
82+
} catch (error) {
83+
deferred.reject(error);
84+
}
8185

8286
return deferred.promise;
8387
},
@@ -92,7 +96,11 @@
9296
authAnonymously: function(options) {
9397
var deferred = this._q.defer();
9498

95-
this._ref.authAnonymously(this._utils.makeNodeResolver(deferred), options);
99+
try {
100+
this._ref.authAnonymously(this._utils.makeNodeResolver(deferred), options);
101+
} catch (error) {
102+
deferred.reject(error);
103+
}
96104

97105
return deferred.promise;
98106
},
@@ -109,7 +117,11 @@
109117
authWithPassword: function(credentials, options) {
110118
var deferred = this._q.defer();
111119

112-
this._ref.authWithPassword(credentials, this._utils.makeNodeResolver(deferred), options);
120+
try {
121+
this._ref.authWithPassword(credentials, this._utils.makeNodeResolver(deferred), options);
122+
} catch (error) {
123+
deferred.reject(error);
124+
}
113125

114126
return deferred.promise;
115127
},
@@ -126,7 +138,11 @@
126138
authWithOAuthPopup: function(provider, options) {
127139
var deferred = this._q.defer();
128140

129-
this._ref.authWithOAuthPopup(provider, this._utils.makeNodeResolver(deferred), options);
141+
try {
142+
this._ref.authWithOAuthPopup(provider, this._utils.makeNodeResolver(deferred), options);
143+
} catch (error) {
144+
deferred.reject(error);
145+
}
130146

131147
return deferred.promise;
132148
},
@@ -143,7 +159,11 @@
143159
authWithOAuthRedirect: function(provider, options) {
144160
var deferred = this._q.defer();
145161

146-
this._ref.authWithOAuthRedirect(provider, this._utils.makeNodeResolver(deferred), options);
162+
try {
163+
this._ref.authWithOAuthRedirect(provider, this._utils.makeNodeResolver(deferred), options);
164+
} catch (error) {
165+
deferred.reject(error);
166+
}
147167

148168
return deferred.promise;
149169
},
@@ -162,7 +182,11 @@
162182
authWithOAuthToken: function(provider, credentials, options) {
163183
var deferred = this._q.defer();
164184

165-
this._ref.authWithOAuthToken(provider, credentials, this._utils.makeNodeResolver(deferred), options);
185+
try {
186+
this._ref.authWithOAuthToken(provider, credentials, this._utils.makeNodeResolver(deferred), options);
187+
} catch (error) {
188+
deferred.reject(error);
189+
}
166190

167191
return deferred.promise;
168192
},
@@ -294,7 +318,11 @@
294318
};
295319
}
296320

297-
this._ref.createUser(credentials, this._utils.makeNodeResolver(deferred));
321+
try {
322+
this._ref.createUser(credentials, this._utils.makeNodeResolver(deferred));
323+
} catch (error) {
324+
deferred.reject(error);
325+
}
298326

299327
return deferred.promise;
300328
},
@@ -324,7 +352,11 @@
324352
};
325353
}
326354

327-
this._ref.changePassword(credentials, this._utils.makeNodeResolver(deferred));
355+
try {
356+
this._ref.changePassword(credentials, this._utils.makeNodeResolver(deferred));
357+
} catch (error) {
358+
deferred.reject(error);
359+
}
328360

329361
return deferred.promise;
330362
},
@@ -351,7 +383,11 @@
351383
};
352384
}
353385

354-
this._ref.removeUser(credentials, this._utils.makeNodeResolver(deferred));
386+
try {
387+
this._ref.removeUser(credentials, this._utils.makeNodeResolver(deferred));
388+
} catch (error) {
389+
deferred.reject(error);
390+
}
355391

356392
return deferred.promise;
357393
},
@@ -366,7 +402,12 @@
366402
*/
367403
sendPasswordResetEmail: function(emailOrCredentials) {
368404
this._log.warn("$sendPasswordResetEmail() has been deprecated in favor of the equivalent $resetPassword().");
369-
return this.resetPassword(emailOrCredentials);
405+
406+
try {
407+
return this.resetPassword(emailOrCredentials);
408+
} catch (error) {
409+
deferred.reject(error);
410+
}
370411
},
371412

372413
/**
@@ -389,7 +430,11 @@
389430
};
390431
}
391432

392-
this._ref.resetPassword(credentials, this._utils.makeNodeResolver(deferred));
433+
try {
434+
this._ref.resetPassword(credentials, this._utils.makeNodeResolver(deferred));
435+
} catch (error) {
436+
deferred.reject(error);
437+
}
393438

394439
return deferred.promise;
395440
}

0 commit comments

Comments
 (0)