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

Commit adb7d34

Browse files
author
Jacob Wenger
committed
Implemented $firebaseAuth.$changeEmail()
1 parent 9939a37 commit adb7d34

File tree

3 files changed

+98
-28
lines changed

3 files changed

+98
-28
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
feature - Added `$firebaseAuth.$changeEmail()` to change the email address associated with an existing account.
12
deprecated - Passing in credentials to the user management methods of `$firebaseAuth` as individual arguments has been deprecated in favor of a single credentials argument.
23
deprecated - Deprecated `$firebaseAuth.$sendPasswordResetEmail()` in favor of the functionally equivalent `$firebaseAuth.$resetPassword()`.

src/FirebaseAuth.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
// User management methods
5252
$createUser: this.createUser.bind(this),
5353
$changePassword: this.changePassword.bind(this),
54+
$changeEmail: this.changeEmail.bind(this),
5455
$removeUser: this.removeUser.bind(this),
5556
$resetPassword: this.resetPassword.bind(this),
5657
$sendPasswordResetEmail: this.sendPasswordResetEmail.bind(this)
@@ -303,7 +304,7 @@
303304
* Changes the password for an email/password user.
304305
*
305306
* @param {Object|string} emailOrCredentials The email of the user whose password is to change
306-
* or an objet containing the email, old password, and new password of the user whose password
307+
* or an object containing the email, old password, and new password of the user whose password
307308
* is to change.
308309
* @param {string} [oldPassword] The current password for the user.
309310
* @param {string} [newPassword] The new password for the user.
@@ -329,6 +330,21 @@
329330
return deferred.promise;
330331
},
331332

333+
/**
334+
* Changes the email for an email/password user.
335+
*
336+
* @param {Object} credentials An object containing the old email, new email, and password of
337+
* the user whose email is to change.
338+
* @return {Promise<>} An empty promise fulfilled once the email change is complete.
339+
*/
340+
changeEmail: function(credentials) {
341+
var deferred = this._q.defer();
342+
343+
this._ref.changeEmail(credentials, this._utils.makeNodeResolver(deferred));
344+
345+
return deferred.promise;
346+
},
347+
332348
/**
333349
* Removes an email/password user.
334350
*

tests/unit/FirebaseAuth.spec.js

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('FirebaseAuth',function(){
2727
['authWithCustomToken','authAnonymously','authWithPassword',
2828
'authWithOAuthPopup','authWithOAuthRedirect','authWithOAuthToken',
2929
'unauth','getAuth','onAuth','offAuth',
30-
'createUser','changePassword','removeUser','resetPassword'
30+
'createUser','changePassword','changeEmail','removeUser','resetPassword'
3131
]);
3232

3333
inject(function(_$firebaseAuth_,_$timeout_){
@@ -197,7 +197,7 @@ describe('FirebaseAuth',function(){
197197
expect(result).toEqual('myResult');
198198
});
199199
});
200-
200+
201201
describe('$authWithOAuthToken',function(){
202202
it('passes provider, token, and options object to underlying method',function(){
203203
var provider = 'facebook';
@@ -361,42 +361,95 @@ describe('FirebaseAuth',function(){
361361
expect(result).toEqual({uid:'1234'});
362362
});
363363
});
364-
365-
describe('$changePassword()',function(){
366-
it('passes email/password to method on backing ref (string args)',function(){
367-
auth.$changePassword('[email protected]','54321','12345');
368-
expect(ref.changePassword).toHaveBeenCalledWith(
369-
{email:'[email protected]',oldPassword:'54321',newPassword:'12345'},
370-
jasmine.any(Function));
371-
});
372364

373-
it('passes email/password to method on backing ref (object arg)',function(){
374-
auth.$changePassword({email:'[email protected]',oldPassword:'54321',newPassword:'12345'});
375-
expect(ref.changePassword).toHaveBeenCalledWith(
376-
{email:'[email protected]',oldPassword:'54321',newPassword:'12345'},
377-
jasmine.any(Function));
378-
});
379-
380-
it('will log a warning if deprecated string args are used',function(){
365+
describe('$changePassword()',function() {
366+
it('passes credentials to method on backing ref (string args)',function() {
367+
auth.$changePassword('[email protected]','54321','12345');
368+
expect(ref.changePassword).toHaveBeenCalledWith({
369+
370+
oldPassword: '54321',
371+
newPassword: '12345'
372+
}, jasmine.any(Function));
373+
});
374+
375+
it('passes credentials to method on backing ref (object arg)',function() {
376+
auth.$changePassword({
377+
378+
oldPassword: '54321',
379+
newPassword: '12345'
380+
});
381+
expect(ref.changePassword).toHaveBeenCalledWith({
382+
383+
oldPassword: '54321',
384+
newPassword: '12345'
385+
}, jasmine.any(Function));
386+
});
387+
388+
it('will log a warning if deprecated string args are used',function() {
381389
auth.$changePassword('[email protected]','54321','12345');
382390
expect(log.warn).toHaveLength(1);
383391
});
384392

385-
it('will reject the promise if authentication fails',function(){
386-
wrapPromise(auth.$changePassword({email:'[email protected]',oldPassword:'54321',newPassword:'12345'}));
393+
it('will reject the promise if authentication fails',function() {
394+
wrapPromise(auth.$changePassword({
395+
396+
oldPassword: '54321',
397+
newPassword: '12345'
398+
}));
387399
callback('changePassword')("bad password");
388400
$timeout.flush();
389401
expect(failure).toEqual("bad password");
390402
});
391403

392-
it('will resolve the promise upon authentication',function(){
393-
wrapPromise(auth.$changePassword('[email protected]','54321','12345'));
404+
it('will resolve the promise upon authentication',function() {
405+
wrapPromise(auth.$changePassword({
406+
407+
oldPassword: '54321',
408+
newPassword: '12345'
409+
}));
394410
callback('changePassword')(null);
395411
$timeout.flush();
396412
expect(status).toEqual('resolved');
397413
});
398414
});
399-
415+
416+
describe('$changeEmail()',function() {
417+
it('passes credentials to method on backing reference', function() {
418+
auth.$changeEmail({
419+
oldEmail: '[email protected]',
420+
newEmail: '[email protected]',
421+
password: '12345'
422+
});
423+
expect(ref.changeEmail).toHaveBeenCalledWith({
424+
oldEmail: '[email protected]',
425+
newEmail: '[email protected]',
426+
password: '12345'
427+
}, jasmine.any(Function));
428+
});
429+
430+
it('will reject the promise if authentication fails',function() {
431+
wrapPromise(auth.$changeEmail({
432+
oldEmail: '[email protected]',
433+
newEmail: '[email protected]',
434+
password: '12345'
435+
}));
436+
callback('changeEmail')("bad password");
437+
$timeout.flush();
438+
expect(failure).toEqual("bad password");
439+
});
440+
441+
it('will resolve the promise upon authentication',function() {
442+
wrapPromise(auth.$changeEmail({
443+
oldEmail: '[email protected]',
444+
newEmail: '[email protected]',
445+
password: '12345'
446+
}));
447+
callback('changeEmail')(null);
448+
$timeout.flush();
449+
expect(status).toEqual('resolved');
450+
});
451+
});
452+
400453
describe('$removeUser()',function(){
401454
it('passes email/password to method on backing ref (string args)',function(){
402455
auth.$removeUser('[email protected]','12345');
@@ -431,7 +484,7 @@ describe('FirebaseAuth',function(){
431484
expect(status).toEqual('resolved');
432485
});
433486
});
434-
487+
435488
describe('$sendPasswordResetEmail()',function(){
436489
it('passes email to method on backing ref (string args)',function(){
437490
auth.$sendPasswordResetEmail('[email protected]');
@@ -451,7 +504,7 @@ describe('FirebaseAuth',function(){
451504
auth.$sendPasswordResetEmail({email:'[email protected]'});
452505
expect(log.warn).toHaveLength(1);
453506
});
454-
507+
455508
it('will log two deprecation warnings if string arg is used',function(){
456509
auth.$sendPasswordResetEmail('[email protected]');
457510
expect(log.warn).toHaveLength(2);
@@ -471,7 +524,7 @@ describe('FirebaseAuth',function(){
471524
expect(status).toEqual('resolved');
472525
});
473526
});
474-
527+
475528
describe('$resetPassword()',function(){
476529
it('passes email to method on backing ref (string args)',function(){
477530
auth.$resetPassword('[email protected]');
@@ -506,4 +559,4 @@ describe('FirebaseAuth',function(){
506559
expect(status).toEqual('resolved');
507560
});
508561
});
509-
});
562+
});

0 commit comments

Comments
 (0)