Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Support updateEmail in firebase_auth #647

Merged
merged 6 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ Hayden Flinner <haydenflinner@gmail.com>
Stefano Rodriguez <hlsroddy@gmail.com>
Salvatore Giordano <salvatoregiordanoo@gmail.com>
Brian Armstrong <brian@flutter.institute>
Fabricio Nogueira <feufeu@gmail.com>
Fabricio Nogueira <feufeu@gmail.com>
Simon Lightfoot <simon@devangels.london>
Ashton Thomas <ashton@acrinta.com>
Thomas Danner <thmsdnnr@gmail.com>
4 changes: 4 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.18

* Adding support for updateEmail in FirebaseAuth.

## 0.5.17

* Adding support for FirebaseUser.delete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public void onMethodCall(MethodCall call, Result result) {
case "updateProfile":
handleUpdateProfile(call, result);
break;
case "updateEmail":
handleUpdateEmail(call, result);
break;
case "startListeningAuthState":
handleStartListeningAuthState(call, result);
break;
Expand Down Expand Up @@ -450,6 +453,28 @@ public void onComplete(@NonNull Task<Void> task) {
});
}

private void handleUpdateEmail(MethodCall call, final Result result) {
@SuppressWarnings("unchecked")
Map<String, String> arguments = (Map<String, String>) call.arguments;
String email = arguments.get("email");

firebaseAuth
.getCurrentUser()
.updateEmail(email)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Exception e = task.getException();
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
} else {
result.success(null);
}
}
});
}

private void handleStartListeningAuthState(MethodCall call, final Result result) {
final int handle = nextHandle++;
FirebaseAuth.AuthStateListener listener =
Expand Down
6 changes: 6 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[changeRequest commitChangesWithCompletion:^(NSError *error) {
[self sendResult:result forUser:nil error:error];
}];
} else if ([@"updateEmail" isEqualToString:call.method]) {
NSString *toEmail = call.arguments[@"email"];
[[FIRAuth auth].currentUser updateEmail:toEmail
completion:^(NSError *_Nullable error) {
[self sendResult:result forUser:nil error:error];
}];
} else if ([@"signInWithCustomToken" isEqualToString:call.method]) {
NSString *token = call.arguments[@"token"];
[[FIRAuth auth] signInWithCustomToken:token
Expand Down
12 changes: 12 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ class FirebaseAuth {
return currentUser;
}

Future<void> updateEmail({
@required String email,
}) async {
assert(email != null);
return await channel.invokeMethod(
'updateEmail',
<String, String>{
'email': email,
},
);
}

Future<void> updateProfile(UserUpdateInfo userUpdateInfo) async {
assert(userUpdateInfo != null);
return await channel.invokeMethod(
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: 0.5.17
version: 0.5.18

flutter:
plugin:
Expand Down
17 changes: 17 additions & 0 deletions packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void main() {
case "updateProfile":
return null;
break;
case "updateEmail":
return null;
break;
case "fetchProvidersForEmail":
return new List<String>(0);
break;
Expand Down Expand Up @@ -373,6 +376,20 @@ void main() {
]);
});

test('updateEmail', () async {
final String updatedEmail = 'atestemail@gmail.com';
auth.updateEmail(email: updatedEmail);
expect(
log,
<Matcher>[
isMethodCall(
'updateEmail',
arguments: <String, String>{'email': updatedEmail},
),
],
);
});

test('signInWithCustomToken', () async {
final FirebaseUser user =
await auth.signInWithCustomToken(token: kMockCustomToken);
Expand Down