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

Commit a5d42fa

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

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

packages/firebase_auth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## 0.6.3
1010

1111
* Add multi app support.
12+
* Adding support for FirebaseUser.unlink(providerId)
1213

1314
## 0.6.2+1
1415

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
@@ -121,6 +121,8 @@ public void onMethodCall(MethodCall call, Result result) {
121121
break;
122122
case "linkWithTwitterCredential":
123123
handleLinkWithTwitterCredential(call, result, getAuth(call));
124+
case "unlink":
125+
handleUnlink(call, result, getAuth(call));
124126
break;
125127
case "linkWithGithubCredential":
126128
handleLinkWithGithubCredential(call, result, getAuth(call));
@@ -461,6 +463,15 @@ private void handleSignInWithCustomToken(
461463
.addOnCompleteListener(new SignInCompleteListener(result));
462464
}
463465

466+
private void handleUnlink(MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
467+
Map<String, String> arguments = call.arguments();
468+
String providerId = arguments.get("providerId");
469+
firebaseAuth
470+
.getCurrentUser()
471+
.unlink(providerId)
472+
.addOnCompleteListener(new SignInCompleteListener(result));
473+
}
474+
464475
private void handleSignOut(MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
465476
firebaseAuth.signOut();
466477
result.success(null);

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
220220
forUser:user
221221
error:error];
222222
}];
223+
} else if ([@"unlink" isEqualToString:call.method]) {
224+
NSString *providerId = call.arguments[@"providerId"];
225+
[[self getAuth:call.arguments].currentUser unlinkFromProvider:providerId
226+
completion:^(FIRUser *user, NSError *error) {
227+
[self sendResult:result
228+
forUser:user
229+
error:error];
230+
}];
223231
} else if ([@"updateEmail" isEqualToString:call.method]) {
224232
NSString *email = call.arguments[@"email"];
225233
[[self getAuth:call.arguments].currentUser updateEmail:email

packages/firebase_auth/lib/firebase_auth.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class FirebaseUserMetadata {
1616
final Map<dynamic, dynamic> _data;
1717

1818
int get creationTimestamp => _data['creationTimestamp'];
19+
1920
int get lastSignInTimestamp => _data['lastSignInTimestamp'];
2021
}
2122

@@ -490,6 +491,20 @@ class FirebaseAuth {
490491
return currentUser;
491492
}
492493

494+
Future<FirebaseUser> unlink({
495+
@required String providerId,
496+
}) async {
497+
final Map<dynamic, dynamic> data = await channel.invokeMethod(
498+
'unlink',
499+
<String, String>{
500+
'app': app.name,
501+
'providerId': providerId,
502+
},
503+
);
504+
final FirebaseUser currentUser = FirebaseUser._(data, app);
505+
return currentUser;
506+
}
507+
493508
/// Sets the user-facing language code for auth operations that can be
494509
/// internationalized, such as [sendEmailVerification]. This language
495510
/// code should follow the conventions defined by the IETF in BCP47.

packages/firebase_auth/test/firebase_auth_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ void main() {
288288
);
289289
});
290290

291+
test('unlink', () async {
292+
final FirebaseUser user = await auth.unlink(
293+
providerId: kMockProviderId,
294+
);
295+
verifyUser(user);
296+
expect(
297+
log,
298+
<Matcher>[
299+
isMethodCall(
300+
'unlink',
301+
arguments: <String, String>{
302+
'app': auth.app.name,
303+
'providerId': kMockProviderId,
304+
},
305+
),
306+
],
307+
);
308+
});
309+
291310
test('signInWithFacebook', () async {
292311
final FirebaseUser user = await auth.signInWithFacebook(
293312
accessToken: kMockAccessToken,

0 commit comments

Comments
 (0)