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

Commit 880415b

Browse files
committed
Added updateEmail and updatePassword functionality to firebase_auth plugin.
1 parent 01faa80 commit 880415b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public void onMethodCall(MethodCall call, Result result) {
108108
case "linkWithFacebookCredential":
109109
handleLinkWithFacebookCredential(call, result);
110110
break;
111+
case "updateEmail":
112+
handleUpdateEmail(call, result);
113+
break;
114+
case "updatePassword":
115+
handleUpdatePassword(call, result);
116+
break;
111117
case "updateProfile":
112118
handleUpdateProfile(call, result);
113119
break;
@@ -408,6 +414,24 @@ public void onComplete(@NonNull Task<GetTokenResult> task) {
408414
});
409415
}
410416

417+
private void handleUpdateEmail(MethodCall call, final Result result) {
418+
@SuppressWarnings("unchecked")
419+
Map<String, String> arguments = (Map<String, String>) call.arguments;
420+
firebaseAuth
421+
.getCurrentUser()
422+
.updateEmail(arguments.get("email"))
423+
.addOnCompleteListener(new TaskVoidCompleteListener(result));
424+
}
425+
426+
private void handleUpdatePassword(MethodCall call, final Result result) {
427+
@SuppressWarnings("unchecked")
428+
Map<String, String> arguments = (Map<String, String>) call.arguments;
429+
firebaseAuth
430+
.getCurrentUser()
431+
.updatePassword(arguments.get("password"))
432+
.addOnCompleteListener(new TaskVoidCompleteListener(result));
433+
}
434+
411435
private void handleUpdateProfile(MethodCall call, final Result result) {
412436
@SuppressWarnings("unchecked")
413437
Map<String, String> arguments = (Map<String, String>) call.arguments;

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
172172
completion:^(FIRUser *user, NSError *error) {
173173
[self sendResult:result forUser:user error:error];
174174
}];
175+
} else if ([@"updateEmail" isEqualToString:call.method]) {
176+
NSString *email = call.arguments[@"email"];
177+
[[FIRAuth auth].currentUser updateEmail:email
178+
completion:^(NSError *error) {
179+
[self sendResult:result forUser:nil error:error];
180+
}];
181+
} else if ([@"updatePassword" isEqualToString:call.method]) {
182+
NSString *password = call.arguments[@"password"];
183+
[[FIRAuth auth].currentUser updatePassword:password
184+
completion:^(NSError *error) {
185+
[self sendResult:result forUser:nil error:error];
186+
}];
175187
} else if ([@"updateProfile" isEqualToString:call.method]) {
176188
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
177189
if (call.arguments[@"displayName"]) {

packages/firebase_auth/lib/firebase_auth.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ class FirebaseUser extends UserInfo {
9090
await FirebaseAuth.channel.invokeMethod('reload');
9191
}
9292

93+
/// Updates the email address of the user.
94+
Future<void> updateEmail(String email) async {
95+
assert(email != null);
96+
return await FirebaseAuth.channel.invokeMethod(
97+
'updateEmail',
98+
<String, String>{'email': email},
99+
);
100+
}
101+
102+
/// Updates the password of the user.
103+
Future<void> updatePassword(String password) async {
104+
assert(password != null);
105+
return await FirebaseAuth.channel.invokeMethod(
106+
'updatePassword',
107+
<String, String>{'password': password},
108+
);
109+
}
110+
93111
@override
94112
String toString() {
95113
return '$runtimeType($_data)';

0 commit comments

Comments
 (0)