Skip to content

Commit bb15df6

Browse files
Revert "Added updatePassword functionality to firebase_auth plugin. (flutter#678)"
This reverts commit 8e1a4e5.
1 parent 3952001 commit bb15df6

6 files changed

Lines changed: 83 additions & 115 deletions

File tree

packages/firebase_auth/CHANGELOG.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
## 0.6.0
2-
3-
* Added support for `updatePassword` in `FirebaseUser`.
4-
* **Breaking Change** Moved `updateEmail` and `updateProfile` to `FirebaseUser`.
5-
This brings the `firebase_auth` package inline with other implementations and documentation.
6-
71
## 0.5.20
82

93
* Replaced usages of guava's: ImmutableList and ImmutableMap with platform
@@ -21,7 +15,7 @@ Collections.unmodifiableList() and Collections.unmodifiableMap().
2115

2216
## 0.5.17
2317

24-
* Adding support for FirebaseUser.delete.
18+
* Adding support for FirebaseUser.delete.
2519

2620
## 0.5.16
2721

packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,12 @@ public void onMethodCall(MethodCall call, Result result) {
111111
case "linkWithFacebookCredential":
112112
handleLinkWithFacebookCredential(call, result);
113113
break;
114-
case "updateEmail":
115-
handleUpdateEmail(call, result);
116-
break;
117-
case "updatePassword":
118-
handleUpdatePassword(call, result);
119-
break;
120114
case "updateProfile":
121115
handleUpdateProfile(call, result);
122116
break;
117+
case "updateEmail":
118+
handleUpdateEmail(call, result);
119+
break;
123120
case "startListeningAuthState":
124121
handleStartListeningAuthState(call, result);
125122
break;
@@ -142,7 +139,6 @@ public void onMethodCall(MethodCall call, Result result) {
142139
}
143140

144141
private void handleSignInWithPhoneNumber(MethodCall call, Result result) {
145-
@SuppressWarnings("unchecked")
146142
Map<String, String> arguments = (Map<String, String>) call.arguments;
147143
String verificationId = arguments.get("verificationId");
148144
String smsCode = arguments.get("smsCode");
@@ -428,24 +424,6 @@ public void onComplete(@NonNull Task<GetTokenResult> task) {
428424
});
429425
}
430426

431-
private void handleUpdateEmail(MethodCall call, final Result result) {
432-
@SuppressWarnings("unchecked")
433-
Map<String, String> arguments = (Map<String, String>) call.arguments;
434-
firebaseAuth
435-
.getCurrentUser()
436-
.updateEmail(arguments.get("email"))
437-
.addOnCompleteListener(new TaskVoidCompleteListener(result));
438-
}
439-
440-
private void handleUpdatePassword(MethodCall call, final Result result) {
441-
@SuppressWarnings("unchecked")
442-
Map<String, String> arguments = (Map<String, String>) call.arguments;
443-
firebaseAuth
444-
.getCurrentUser()
445-
.updatePassword(arguments.get("password"))
446-
.addOnCompleteListener(new TaskVoidCompleteListener(result));
447-
}
448-
449427
private void handleUpdateProfile(MethodCall call, final Result result) {
450428
@SuppressWarnings("unchecked")
451429
Map<String, String> arguments = (Map<String, String>) call.arguments;
@@ -461,7 +439,40 @@ private void handleUpdateProfile(MethodCall call, final Result result) {
461439
firebaseAuth
462440
.getCurrentUser()
463441
.updateProfile(builder.build())
464-
.addOnCompleteListener(new TaskVoidCompleteListener(result));
442+
.addOnCompleteListener(
443+
new OnCompleteListener<Void>() {
444+
@Override
445+
public void onComplete(@NonNull Task<Void> task) {
446+
if (!task.isSuccessful()) {
447+
Exception e = task.getException();
448+
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
449+
} else {
450+
result.success(null);
451+
}
452+
}
453+
});
454+
}
455+
456+
private void handleUpdateEmail(MethodCall call, final Result result) {
457+
@SuppressWarnings("unchecked")
458+
Map<String, String> arguments = (Map<String, String>) call.arguments;
459+
String email = arguments.get("email");
460+
461+
firebaseAuth
462+
.getCurrentUser()
463+
.updateEmail(email)
464+
.addOnCompleteListener(
465+
new OnCompleteListener<Void>() {
466+
@Override
467+
public void onComplete(@NonNull Task<Void> task) {
468+
if (!task.isSuccessful()) {
469+
Exception e = task.getException();
470+
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
471+
} else {
472+
result.success(null);
473+
}
474+
}
475+
});
465476
}
466477

467478
private void handleStartListeningAuthState(MethodCall call, final Result result) {

packages/firebase_auth/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class _MyHomePageState extends State<MyHomePage> {
9999
(AuthException authException) {
100100
setState(() {
101101
_message = Future<String>.value(
102-
'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}');
102+
'Phone numbber verification failed. Code: ${authException.code}. Message: ${authException.message}');
103103
});
104104
};
105105

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
176176
completion:^(FIRUser *user, NSError *error) {
177177
[self sendResult:result forUser:user error:error];
178178
}];
179-
} else if ([@"updateEmail" isEqualToString:call.method]) {
180-
NSString *email = call.arguments[@"email"];
181-
[[FIRAuth auth].currentUser updateEmail:email
182-
completion:^(NSError *error) {
183-
[self sendResult:result forUser:nil error:error];
184-
}];
185-
} else if ([@"updatePassword" isEqualToString:call.method]) {
186-
NSString *password = call.arguments[@"password"];
187-
[[FIRAuth auth].currentUser updatePassword:password
188-
completion:^(NSError *error) {
189-
[self sendResult:result forUser:nil error:error];
190-
}];
191179
} else if ([@"updateProfile" isEqualToString:call.method]) {
192180
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
193181
if (call.arguments[@"displayName"]) {
@@ -199,6 +187,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
199187
[changeRequest commitChangesWithCompletion:^(NSError *error) {
200188
[self sendResult:result forUser:nil error:error];
201189
}];
190+
} else if ([@"updateEmail" isEqualToString:call.method]) {
191+
NSString *toEmail = call.arguments[@"email"];
192+
[[FIRAuth auth].currentUser updateEmail:toEmail
193+
completion:^(NSError *_Nullable error) {
194+
[self sendResult:result forUser:nil error:error];
195+
}];
202196
} else if ([@"signInWithCustomToken" isEqualToString:call.method]) {
203197
NSString *token = call.arguments[@"token"];
204198
[[FIRAuth auth] signInWithCustomToken:token

packages/firebase_auth/lib/firebase_auth.dart

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,6 @@ class FirebaseUser extends UserInfo {
9595
await FirebaseAuth.channel.invokeMethod('delete');
9696
}
9797

98-
/// Updates the email address of the user.
99-
Future<void> updateEmail(String email) async {
100-
assert(email != null);
101-
return await FirebaseAuth.channel.invokeMethod(
102-
'updateEmail',
103-
<String, String>{'email': email},
104-
);
105-
}
106-
107-
/// Updates the password of the user.
108-
Future<void> updatePassword(String password) async {
109-
assert(password != null);
110-
return await FirebaseAuth.channel.invokeMethod(
111-
'updatePassword',
112-
<String, String>{'password': password},
113-
);
114-
}
115-
116-
/// Updates the user profile information.
117-
Future<void> updateProfile(UserUpdateInfo userUpdateInfo) async {
118-
assert(userUpdateInfo != null);
119-
return await FirebaseAuth.channel.invokeMethod(
120-
'updateProfile',
121-
userUpdateInfo._updateData,
122-
);
123-
}
124-
12598
@override
12699
String toString() {
127100
return '$runtimeType($_data)';
@@ -395,6 +368,26 @@ class FirebaseAuth {
395368
return currentUser;
396369
}
397370

371+
Future<void> updateEmail({
372+
@required String email,
373+
}) async {
374+
assert(email != null);
375+
return await channel.invokeMethod(
376+
'updateEmail',
377+
<String, String>{
378+
'email': email,
379+
},
380+
);
381+
}
382+
383+
Future<void> updateProfile(UserUpdateInfo userUpdateInfo) async {
384+
assert(userUpdateInfo != null);
385+
return await channel.invokeMethod(
386+
'updateProfile',
387+
userUpdateInfo._updateData,
388+
);
389+
}
390+
398391
/// Links google account with current user and returns [Future<FirebaseUser>]
399392
///
400393
/// throws [PlatformException] when

packages/firebase_auth/test/firebase_auth_test.dart

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ void main() {
4141
return mockHandleId++;
4242
break;
4343
case "sendPasswordResetEmail":
44-
case "updateEmail":
45-
case "updatePassword":
4644
case "updateProfile":
4745
return null;
4846
break;
47+
case "updateEmail":
48+
return null;
49+
break;
4950
case "fetchProvidersForEmail":
5051
return List<String>(0);
5152
break;
@@ -358,52 +359,13 @@ void main() {
358359
);
359360
});
360361

361-
test('updateEmail', () async {
362-
final FirebaseUser user = await auth.currentUser();
363-
await user.updateEmail(kMockEmail);
364-
expect(log, <Matcher>[
365-
isMethodCall(
366-
'currentUser',
367-
arguments: null,
368-
),
369-
isMethodCall(
370-
'updateEmail',
371-
arguments: <String, String>{
372-
'email': kMockEmail,
373-
},
374-
),
375-
]);
376-
});
377-
378-
test('updatePassword', () async {
379-
final FirebaseUser user = await auth.currentUser();
380-
await user.updatePassword(kMockPassword);
381-
expect(log, <Matcher>[
382-
isMethodCall(
383-
'currentUser',
384-
arguments: null,
385-
),
386-
isMethodCall(
387-
'updatePassword',
388-
arguments: <String, String>{
389-
'password': kMockPassword,
390-
},
391-
),
392-
]);
393-
});
394-
395362
test('updateProfile', () async {
396363
final UserUpdateInfo userUpdateInfo = UserUpdateInfo();
397364
userUpdateInfo.photoUrl = kMockPhotoUrl;
398365
userUpdateInfo.displayName = kMockDisplayName;
399366

400-
final FirebaseUser user = await auth.currentUser();
401-
await user.updateProfile(userUpdateInfo);
367+
await auth.updateProfile(userUpdateInfo);
402368
expect(log, <Matcher>[
403-
isMethodCall(
404-
'currentUser',
405-
arguments: null,
406-
),
407369
isMethodCall(
408370
'updateProfile',
409371
arguments: <String, String>{
@@ -414,6 +376,20 @@ void main() {
414376
]);
415377
});
416378

379+
test('updateEmail', () async {
380+
final String updatedEmail = 'atestemail@gmail.com';
381+
auth.updateEmail(email: updatedEmail);
382+
expect(
383+
log,
384+
<Matcher>[
385+
isMethodCall(
386+
'updateEmail',
387+
arguments: <String, String>{'email': updatedEmail},
388+
),
389+
],
390+
);
391+
});
392+
417393
test('signInWithCustomToken', () async {
418394
final FirebaseUser user =
419395
await auth.signInWithCustomToken(token: kMockCustomToken);

0 commit comments

Comments
 (0)