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

Commit db222d0

Browse files
committed
Merge pull request #563 from firebase/jw-auth-creds
Removed deprecated auth methods and functionality
2 parents b48e036 + b88d273 commit db222d0

File tree

2 files changed

+46
-163
lines changed

2 files changed

+46
-163
lines changed

src/FirebaseAuth.js

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
$changePassword: this.changePassword.bind(this),
5454
$changeEmail: this.changeEmail.bind(this),
5555
$removeUser: this.removeUser.bind(this),
56-
$resetPassword: this.resetPassword.bind(this),
57-
$sendPasswordResetEmail: this.sendPasswordResetEmail.bind(this)
56+
$resetPassword: this.resetPassword.bind(this)
5857
};
5958

6059
return this._object;
@@ -303,24 +302,16 @@
303302
* wish to log in as the newly created user, call $authWithPassword() after the promise for
304303
* this method has been resolved.
305304
*
306-
* @param {Object|string} emailOrCredentials The email of the user to create or an object
307-
* containing the email and password of the user to create.
308-
* @param {string} [password] The password for the user to create.
305+
* @param {Object} credentials An object containing the email and password of the user to create.
309306
* @return {Promise<Object>} A promise fulfilled with the user object, which contains the
310307
* uid of the created user.
311308
*/
312-
createUser: function(emailOrCredentials, password) {
309+
createUser: function(credentials) {
313310
var deferred = this._q.defer();
314311

315-
// Allow this method to take a single credentials argument or two separate string arguments
316-
var credentials = emailOrCredentials;
317-
if (typeof emailOrCredentials === "string") {
318-
this._log.warn("Passing in credentials to $createUser() as individual arguments has been deprecated in favor of a single credentials argument. See the AngularFire API reference for details.");
319-
320-
credentials = {
321-
email: emailOrCredentials,
322-
password: password
323-
};
312+
// Throw an error if they are trying to pass in separate string arguments
313+
if (typeof credentials === "string") {
314+
throw new Error("$createUser() expects an object containing 'email' and 'password', but got a string.");
324315
}
325316

326317
try {
@@ -335,26 +326,16 @@
335326
/**
336327
* Changes the password for an email/password user.
337328
*
338-
* @param {Object|string} emailOrCredentials The email of the user whose password is to change
339-
* or an object containing the email, old password, and new password of the user whose password
340-
* is to change.
341-
* @param {string} [oldPassword] The current password for the user.
342-
* @param {string} [newPassword] The new password for the user.
329+
* @param {Object} credentials An object containing the email, old password, and new password of
330+
* the user whose password is to change.
343331
* @return {Promise<>} An empty promise fulfilled once the password change is complete.
344332
*/
345-
changePassword: function(emailOrCredentials, oldPassword, newPassword) {
333+
changePassword: function(credentials) {
346334
var deferred = this._q.defer();
347335

348-
// Allow this method to take a single credentials argument or three separate string arguments
349-
var credentials = emailOrCredentials;
350-
if (typeof emailOrCredentials === "string") {
351-
this._log.warn("Passing in credentials to $changePassword() as individual arguments has been deprecated in favor of a single credentials argument. See the AngularFire API reference for details.");
352-
353-
credentials = {
354-
email: emailOrCredentials,
355-
oldPassword: oldPassword,
356-
newPassword: newPassword
357-
};
336+
// Throw an error if they are trying to pass in separate string arguments
337+
if (typeof credentials === "string") {
338+
throw new Error("$changePassword() expects an object containing 'email', 'oldPassword', and 'newPassword', but got a string.");
358339
}
359340

360341
try {
@@ -375,7 +356,7 @@
375356
*/
376357
changeEmail: function(credentials) {
377358
if (typeof this._ref.changeEmail !== 'function') {
378-
throw new Error('$firebaseAuth.$changeEmail() requires Firebase version 2.1.0 or greater.');
359+
throw new Error("$changeEmail() expects an object containing 'oldEmail', 'newEmail', and 'password', but got a string.");
379360
}
380361

381362
var deferred = this._q.defer();
@@ -392,23 +373,15 @@
392373
/**
393374
* Removes an email/password user.
394375
*
395-
* @param {Object|string} emailOrCredentials The email of the user to remove or an object
396-
* containing the email and password of the user to remove.
397-
* @param {string} [password] The password of the user to remove.
376+
* @param {Object} credentials An object containing the email and password of the user to remove.
398377
* @return {Promise<>} An empty promise fulfilled once the user is removed.
399378
*/
400-
removeUser: function(emailOrCredentials, password) {
379+
removeUser: function(credentials) {
401380
var deferred = this._q.defer();
402381

403-
// Allow this method to take a single credentials argument or two separate string arguments
404-
var credentials = emailOrCredentials;
405-
if (typeof emailOrCredentials === "string") {
406-
this._log.warn("Passing in credentials to $removeUser() as individual arguments has been deprecated in favor of a single credentials argument. See the AngularFire API reference for details.");
407-
408-
credentials = {
409-
email: emailOrCredentials,
410-
password: password
411-
};
382+
// Throw an error if they are trying to pass in separate string arguments
383+
if (typeof credentials === "string") {
384+
throw new Error("$removeUser() expects an object containing 'email' and 'password', but got a string.");
412385
}
413386

414387
try {
@@ -420,44 +393,20 @@
420393
return deferred.promise;
421394
},
422395

423-
/**
424-
* Sends a password reset email to an email/password user. [DEPRECATED]
425-
*
426-
* @deprecated
427-
* @param {Object|string} emailOrCredentials The email of the user to send a reset password
428-
* email to or an object containing the email of the user to send a reset password email to.
429-
* @return {Promise<>} An empty promise fulfilled once the reset password email is sent.
430-
*/
431-
sendPasswordResetEmail: function(emailOrCredentials) {
432-
this._log.warn("$sendPasswordResetEmail() has been deprecated in favor of the equivalent $resetPassword().");
433-
434-
try {
435-
return this.resetPassword(emailOrCredentials);
436-
} catch (error) {
437-
return this._q(function(resolve, reject) {
438-
return reject(error);
439-
});
440-
}
441-
},
442396

443397
/**
444398
* Sends a password reset email to an email/password user.
445399
*
446-
* @param {Object|string} emailOrCredentials The email of the user to send a reset password
447-
* email to or an object containing the email of the user to send a reset password email to.
400+
* @param {Object} credentials An object containing the email of the user to send a reset
401+
* password email to.
448402
* @return {Promise<>} An empty promise fulfilled once the reset password email is sent.
449403
*/
450-
resetPassword: function(emailOrCredentials) {
404+
resetPassword: function(credentials) {
451405
var deferred = this._q.defer();
452406

453-
// Allow this method to take a single credentials argument or a single string argument
454-
var credentials = emailOrCredentials;
455-
if (typeof emailOrCredentials === "string") {
456-
this._log.warn("Passing in credentials to $resetPassword() as individual arguments has been deprecated in favor of a single credentials argument. See the AngularFire API reference for details.");
457-
458-
credentials = {
459-
email: emailOrCredentials
460-
};
407+
// Throw an error if they are trying to pass in a string argument
408+
if (typeof credentials === "string") {
409+
throw new Error("$resetPassword() expects an object containing 'email', but got a string.");
461410
}
462411

463412
try {

tests/unit/FirebaseAuth.spec.js

Lines changed: 22 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -320,25 +320,19 @@ describe('FirebaseAuth',function(){
320320
});
321321

322322
describe('$createUser()',function(){
323-
it('passes email/password to method on backing ref (string args)',function(){
324-
auth.$createUser('[email protected]','12345');
325-
expect(ref.createUser).toHaveBeenCalledWith(
326-
{email:'[email protected]',password:'12345'},
327-
jasmine.any(Function));
328-
});
329-
330-
it('will log a warning if deprecated string arguments are used',function(){
331-
auth.$createUser('[email protected]','12345');
332-
expect(log.warn).toHaveLength(1);
333-
});
334-
335-
it('passes email/password to method on backing ref (object arg)',function(){
323+
it('passes email/password to method on backing ref',function(){
336324
auth.$createUser({email:'[email protected]',password:'12345'});
337325
expect(ref.createUser).toHaveBeenCalledWith(
338326
{email:'[email protected]',password:'12345'},
339327
jasmine.any(Function));
340328
});
341329

330+
it('throws error given string arguments',function(){
331+
expect(function() {
332+
auth.$createUser('[email protected]', '12345');
333+
}).toThrow();
334+
});
335+
342336
it('will reject the promise if creation fails',function(){
343337
wrapPromise(auth.$createUser({email:'[email protected]', password:'12345'}));
344338
callback('createUser')("I've got the same combination on my luggage");
@@ -362,16 +356,7 @@ describe('FirebaseAuth',function(){
362356
});
363357

364358
describe('$changePassword()',function() {
365-
it('passes credentials to method on backing ref (string args)',function() {
366-
auth.$changePassword('[email protected]','54321','12345');
367-
expect(ref.changePassword).toHaveBeenCalledWith({
368-
369-
oldPassword: '54321',
370-
newPassword: '12345'
371-
}, jasmine.any(Function));
372-
});
373-
374-
it('passes credentials to method on backing ref (object arg)',function() {
359+
it('passes credentials to method on backing ref',function() {
375360
auth.$changePassword({
376361
377362
oldPassword: '54321',
@@ -384,9 +369,10 @@ describe('FirebaseAuth',function(){
384369
}, jasmine.any(Function));
385370
});
386371

387-
it('will log a warning if deprecated string args are used',function() {
388-
auth.$changePassword('[email protected]','54321','12345');
389-
expect(log.warn).toHaveLength(1);
372+
it('throws error given string arguments',function(){
373+
expect(function() {
374+
auth.$changePassword('[email protected]', '54321', '12345');
375+
}).toThrow();
390376
});
391377

392378
it('will reject the promise if the password change fails',function() {
@@ -450,23 +436,17 @@ describe('FirebaseAuth',function(){
450436
});
451437

452438
describe('$removeUser()',function(){
453-
it('passes email/password to method on backing ref (string args)',function(){
454-
auth.$removeUser('[email protected]','12345');
455-
expect(ref.removeUser).toHaveBeenCalledWith(
456-
{email:'[email protected]',password:'12345'},
457-
jasmine.any(Function));
458-
});
459-
460-
it('passes email/password to method on backing ref (object arg)',function(){
439+
it('passes email/password to method on backing ref',function(){
461440
auth.$removeUser({email:'[email protected]',password:'12345'});
462441
expect(ref.removeUser).toHaveBeenCalledWith(
463442
{email:'[email protected]',password:'12345'},
464443
jasmine.any(Function));
465444
});
466445

467-
it('will log a warning if deprecated string args are used',function(){
468-
auth.$removeUser('[email protected]','12345');
469-
expect(log.warn).toHaveLength(1);
446+
it('throws error given string arguments',function(){
447+
expect(function() {
448+
auth.$removeUser('[email protected]', '12345');
449+
}).toThrow();
470450
});
471451

472452
it('will reject the promise if there is an error',function(){
@@ -484,64 +464,18 @@ describe('FirebaseAuth',function(){
484464
});
485465
});
486466

487-
describe('$sendPasswordResetEmail()',function(){
488-
it('passes email to method on backing ref (string args)',function(){
489-
auth.$sendPasswordResetEmail('[email protected]');
490-
expect(ref.resetPassword).toHaveBeenCalledWith(
491-
{email:'[email protected]'},
492-
jasmine.any(Function));
493-
});
494-
495-
it('passes email to method on backing ref (object arg)',function(){
496-
auth.$sendPasswordResetEmail({email:'[email protected]'});
497-
expect(ref.resetPassword).toHaveBeenCalledWith(
498-
{email:'[email protected]'},
499-
jasmine.any(Function));
500-
});
501-
502-
it('will log a deprecation warning (object arg)',function(){
503-
auth.$sendPasswordResetEmail({email:'[email protected]'});
504-
expect(log.warn).toHaveLength(1);
505-
});
506-
507-
it('will log two deprecation warnings if string arg is used',function(){
508-
auth.$sendPasswordResetEmail('[email protected]');
509-
expect(log.warn).toHaveLength(2);
510-
});
511-
512-
it('will reject the promise if reset action fails',function(){
513-
wrapPromise(auth.$sendPasswordResetEmail({email:'[email protected]'}));
514-
callback('resetPassword')("user not found");
515-
$timeout.flush();
516-
expect(failure).toEqual("user not found");
517-
});
518-
519-
it('will resolve the promise upon success',function(){
520-
wrapPromise(auth.$sendPasswordResetEmail({email:'[email protected]'}));
521-
callback('resetPassword')(null);
522-
$timeout.flush();
523-
expect(status).toEqual('resolved');
524-
});
525-
});
526-
527467
describe('$resetPassword()',function(){
528-
it('passes email to method on backing ref (string args)',function(){
529-
auth.$resetPassword('[email protected]');
530-
expect(ref.resetPassword).toHaveBeenCalledWith(
531-
{email:'[email protected]'},
532-
jasmine.any(Function));
533-
});
534-
535-
it('passes email to method on backing ref (object arg)',function(){
468+
it('passes email to method on backing ref',function(){
536469
auth.$resetPassword({email:'[email protected]'});
537470
expect(ref.resetPassword).toHaveBeenCalledWith(
538471
{email:'[email protected]'},
539472
jasmine.any(Function));
540473
});
541474

542-
it('will log a warning if deprecated string arg is used',function(){
543-
auth.$resetPassword('[email protected]');
544-
expect(log.warn).toHaveLength(1);
475+
it('throws error given string arguments',function(){
476+
expect(function() {
477+
auth.$resetPassword('[email protected]');
478+
}).toThrow();
545479
});
546480

547481
it('will reject the promise if reset action fails',function(){

0 commit comments

Comments
 (0)