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

Commit 27dcdd9

Browse files
committed
Adding support for FirebaseUser.unlink(providerId)
* Unlink an auth provider from a user account
1 parent 1aef7d9 commit 27dcdd9

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public void onMethodCall(MethodCall call, Result result) {
111111
case "linkWithFacebookCredential":
112112
handleLinkWithFacebookCredential(call, result);
113113
break;
114+
case "unlink":
115+
handleUnlink(call, result);
116+
break;
114117
case "updateProfile":
115118
handleUpdateProfile(call, result);
116119
break;
@@ -372,6 +375,16 @@ private void handleLinkWithFacebookCredential(MethodCall call, final Result resu
372375
.addOnCompleteListener(new SignInCompleteListener(result));
373376
}
374377

378+
private void handleUnlink(MethodCall call, final Result result) {
379+
@SuppressWarnings("unchecked")
380+
Map<String, String> arguments = (Map<String, String>) call.arguments;
381+
String providerId = arguments.get("providerId");
382+
firebaseAuth
383+
.getCurrentUser()
384+
.unlink(providerId)
385+
.addOnCompleteListener(new SignInCompleteListener(result));
386+
}
387+
375388
private void handleSignInWithFacebook(MethodCall call, final Result result) {
376389
@SuppressWarnings("unchecked")
377390
Map<String, String> arguments = (Map<String, String>) call.arguments;

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ - (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 ([@"unlink" isEqualToString:call.method]) {
180+
NSString *providerId = call.arguments[@"providerId"];
181+
[[FIRAuth auth].currentUser unlinkFromProvider:providerId
182+
completion:^(FIRUser *user, NSError *error) {
183+
[self sendResult:result forUser:user error:error];
184+
}];
179185
} else if ([@"updateProfile" isEqualToString:call.method]) {
180186
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
181187
if (call.arguments[@"displayName"]) {

packages/firebase_auth/lib/firebase_auth.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,19 @@ class FirebaseAuth {
427427
return currentUser;
428428
}
429429

430+
Future<FirebaseUser> unlink({
431+
@required String providerId,
432+
}) async {
433+
final Map<dynamic, dynamic> data = await channel.invokeMethod(
434+
'unlink',
435+
<String, String>{
436+
'providerId': providerId,
437+
},
438+
);
439+
final FirebaseUser currentUser = FirebaseUser._(data);
440+
return currentUser;
441+
}
442+
430443
/// Sets the user-facing language code for auth operations that can be
431444
/// internationalized, such as [sendEmailVerification]. This language
432445
/// code should follow the conventions defined by the IETF in BCP47.

packages/firebase_auth/test/firebase_auth_test.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ void main() {
247247
);
248248
});
249249

250+
test('unlink', () async {
251+
final FirebaseUser user = await auth.unlink(
252+
providerId: kMockProviderId,
253+
);
254+
verifyUser(user);
255+
expect(
256+
log,
257+
<Matcher>[
258+
isMethodCall(
259+
'unlink',
260+
arguments: <String, String>{
261+
'providerId': kMockProviderId,
262+
},
263+
),
264+
],
265+
);
266+
});
267+
250268
test('signInWithFacebook', () async {
251269
final FirebaseUser user = await auth.signInWithFacebook(
252270
accessToken: kMockAccessToken,
@@ -378,7 +396,7 @@ void main() {
378396

379397
test('updateEmail', () async {
380398
final String updatedEmail = '[email protected]';
381-
auth.updateEmail(email: updatedEmail);
399+
await auth.updateEmail(email: updatedEmail);
382400
expect(
383401
log,
384402
<Matcher>[

0 commit comments

Comments
 (0)