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

Commit 85e9f76

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

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

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/lib/firebase_auth.dart

Lines changed: 14 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,19 @@ 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+
'providerId': providerId,
501+
},
502+
);
503+
final FirebaseUser currentUser = FirebaseUser._(data, app);
504+
return currentUser;
505+
}
506+
493507
/// Sets the user-facing language code for auth operations that can be
494508
/// internationalized, such as [sendEmailVerification]. This language
495509
/// 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
@@ -288,6 +288,24 @@ 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+
'providerId': kMockProviderId,
303+
},
304+
),
305+
],
306+
);
307+
});
308+
291309
test('signInWithFacebook', () async {
292310
final FirebaseUser user = await auth.signInWithFacebook(
293311
accessToken: kMockAccessToken,

0 commit comments

Comments
 (0)