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

Commit 35da956

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

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

packages/firebase_auth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.6.2
22

33
* Add access to user metadata.
4+
* Adding support for FirebaseUser.unlink(providerId)
45

56
## 0.6.1
67

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public void onMethodCall(MethodCall call, Result result) {
113113
break;
114114
case "linkWithTwitterCredential":
115115
handleLinkWithTwitterCredential(call, result);
116+
case "unlink":
117+
handleUnlink(call, result);
116118
break;
117119
case "updateEmail":
118120
handleUpdateEmail(call, result);
@@ -418,6 +420,15 @@ private void handleSignInWithCustomToken(MethodCall call, final Result result) {
418420
.addOnCompleteListener(new SignInCompleteListener(result));
419421
}
420422

423+
private void handleUnlink(MethodCall call, final Result result) {
424+
Map<String, String> arguments = call.arguments();
425+
String providerId = arguments.get("providerId");
426+
firebaseAuth
427+
.getCurrentUser()
428+
.unlink(providerId)
429+
.addOnCompleteListener(new SignInCompleteListener(result));
430+
}
431+
421432
private void handleSignOut(MethodCall call, final Result result) {
422433
firebaseAuth.signOut();
423434
result.success(null);

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
185185
completion:^(FIRUser *user, NSError *error) {
186186
[self sendResult:result forUser:user error:error];
187187
}];
188+
} else if ([@"unlink" isEqualToString:call.method]) {
189+
NSString *providerId = call.arguments[@"providerId"];
190+
[[FIRAuth auth].currentUser unlinkFromProvider:providerId
191+
completion:^(FIRUser *user, NSError *error) {
192+
[self sendResult:result forUser:user error:error];
193+
}];
188194
} else if ([@"updateEmail" isEqualToString:call.method]) {
189195
NSString *email = call.arguments[@"email"];
190196
[[FIRAuth auth].currentUser updateEmail:email
@@ -197,7 +203,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
197203
completion:^(NSError *error) {
198204
[self sendResult:result forUser:nil error:error];
199205
}];
200-
201206
} else if ([@"updateProfile" isEqualToString:call.method]) {
202207
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
203208
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
@@ -463,6 +463,19 @@ class FirebaseAuth {
463463
return currentUser;
464464
}
465465

466+
Future<FirebaseUser> unlink({
467+
@required String providerId,
468+
}) async {
469+
final Map<dynamic, dynamic> data = await channel.invokeMethod(
470+
'unlink',
471+
<String, String>{
472+
'providerId': providerId,
473+
},
474+
);
475+
final FirebaseUser currentUser = FirebaseUser._(data);
476+
return currentUser;
477+
}
478+
466479
/// Sets the user-facing language code for auth operations that can be
467480
/// internationalized, such as [sendEmailVerification]. This language
468481
/// code should follow the conventions defined by the IETF in BCP47.

packages/firebase_auth/test/firebase_auth_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ void main() {
268268
);
269269
});
270270

271+
test('unlink', () async {
272+
final FirebaseUser user = await auth.unlink(
273+
providerId: kMockProviderId,
274+
);
275+
verifyUser(user);
276+
expect(
277+
log,
278+
<Matcher>[
279+
isMethodCall(
280+
'unlink',
281+
arguments: <String, String>{
282+
'providerId': kMockProviderId,
283+
},
284+
),
285+
],
286+
);
287+
});
288+
271289
test('signInWithFacebook', () async {
272290
final FirebaseUser user = await auth.signInWithFacebook(
273291
accessToken: kMockAccessToken,

0 commit comments

Comments
 (0)