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

Commit 910b42b

Browse files
author
jacobawenger
committed
Updated API signatures of user management methods
1 parent b1de5aa commit 910b42b

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

src/FirebaseAuth.js

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
$createUser: this.createUser.bind(this),
5252
$changePassword: this.changePassword.bind(this),
5353
$removeUser: this.removeUser.bind(this),
54-
$sendPasswordResetEmail: this.sendPasswordResetEmail.bind(this)
54+
$resetPassword: this.resetPassword.bind(this),
55+
$sendPasswordResetEmail: this.resetPassword.bind(this)
5556
};
5657

5758
return this._object;
@@ -196,13 +197,19 @@
196197
// Creates a new email/password user. Note that this function only creates the user, if you
197198
// wish to log in as the newly created user, call $authWithPassword() after the promise for
198199
// this method has been resolved.
199-
createUser: function(email, password) {
200+
createUser: function(emailOrCredentials, password) {
200201
var deferred = this._q.defer();
201202

202-
this._ref.createUser({
203-
email: email,
204-
password: password
205-
}, function(error) {
203+
// Allow this method to take a single credentials argument or two separate string arguments
204+
var credentials = emailOrCredentials;
205+
if (typeof emailOrCredentials === "string") {
206+
credentials = {
207+
email: emailOrCredentials,
208+
password: password
209+
};
210+
}
211+
212+
this._ref.createUser(credentials, function(error) {
206213
if (error !== null) {
207214
deferred.reject(error);
208215
} else {
@@ -214,33 +221,44 @@
214221
},
215222

216223
// Changes the password for an email/password user.
217-
changePassword: function(email, oldPassword, newPassword) {
224+
changePassword: function(emailOrCredentials, oldPassword, newPassword) {
218225
var deferred = this._q.defer();
219226

220-
this._ref.changePassword({
221-
email: email,
222-
oldPassword: oldPassword,
223-
newPassword: newPassword
224-
}, function(error) {
225-
if (error !== null) {
226-
deferred.reject(error);
227-
} else {
228-
deferred.resolve();
229-
}
227+
// Allow this method to take a single credentials argument or three separate string arguments
228+
var credentials = emailOrCredentials;
229+
if (typeof emailOrCredentials === "string") {
230+
credentials = {
231+
email: emailOrCredentials,
232+
oldPassword: oldPassword,
233+
newPassword: newPassword
234+
};
235+
}
236+
237+
this._ref.changePassword(credentials, function(error) {
238+
if (error !== null) {
239+
deferred.reject(error);
240+
} else {
241+
deferred.resolve();
230242
}
231-
);
243+
});
232244

233245
return deferred.promise;
234246
},
235247

236248
// Removes an email/password user.
237-
removeUser: function(email, password) {
249+
removeUser: function(emailOrCredentials, password) {
238250
var deferred = this._q.defer();
239251

240-
this._ref.removeUser({
241-
email: email,
242-
password: password
243-
}, function(error) {
252+
// Allow this method to take a single credentials argument or two separate string arguments
253+
var credentials = emailOrCredentials;
254+
if (typeof emailOrCredentials === "string") {
255+
credentials = {
256+
email: emailOrCredentials,
257+
password: password
258+
};
259+
}
260+
261+
this._ref.removeUser(credentials, function(error) {
244262
if (error !== null) {
245263
deferred.reject(error);
246264
} else {
@@ -252,12 +270,18 @@
252270
},
253271

254272
// Sends a password reset email to an email/password user.
255-
sendPasswordResetEmail: function(email) {
273+
resetPassword: function(emailOrCredentials) {
256274
var deferred = this._q.defer();
257275

258-
this._ref.resetPassword({
259-
email: email
260-
}, function(error) {
276+
// Allow this method to take a single credentials argument or a single string argument
277+
var credentials = emailOrCredentials;
278+
if (typeof emailOrCredentials === "string") {
279+
credentials = {
280+
email: emailOrCredentials
281+
};
282+
}
283+
284+
this._ref.resetPassword(credentials, function(error) {
261285
if (error !== null) {
262286
deferred.reject(error);
263287
} else {

0 commit comments

Comments
 (0)