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

[firebase_auth] Adding support for FirebaseUser.unlink(providerId) #703

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.7

* Adding support for FirebaseUser.unlink(providerId)

## 0.6.5

* Fixing async method `verifyPhoneNumber`, that would never return even in a successful call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public void onMethodCall(MethodCall call, Result result) {
break;
case "linkWithTwitterCredential":
handleLinkWithTwitterCredential(call, result, getAuth(call));
case "unlink":
handleUnlink(call, result, getAuth(call));
break;
case "linkWithGithubCredential":
handleLinkWithGithubCredential(call, result, getAuth(call));
Expand Down Expand Up @@ -538,6 +540,15 @@ private void handleSignInWithCustomToken(
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleUnlink(MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String providerId = arguments.get("providerId");
firebaseAuth
.getCurrentUser()
.unlink(providerId)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleSignOut(MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
firebaseAuth.signOut();
result.success(null);
Expand Down
8 changes: 8 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
forUser:user
error:error];
}];
} else if ([@"unlink" isEqualToString:call.method]) {
NSString *providerId = call.arguments[@"providerId"];
[[self getAuth:call.arguments].currentUser unlinkFromProvider:providerId
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result
forUser:user
error:error];
}];
} else if ([@"updateEmail" isEqualToString:call.method]) {
NSString *email = call.arguments[@"email"];
[[self getAuth:call.arguments].currentUser updateEmail:email
Expand Down
14 changes: 14 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,20 @@ class FirebaseAuth {
<String, String>{'app': app.name, 'token': token});
}

Future<FirebaseUser> unlink({
@required String providerId,
}) async {
final Map<dynamic, dynamic> data = await channel.invokeMethod(
'unlink',
<String, String>{
'app': app.name,
'providerId': providerId,
},
);
final FirebaseUser currentUser = FirebaseUser._(data, app);
return currentUser;
}

/// Sets the user-facing language code for auth operations that can be
/// internationalized, such as [sendEmailVerification]. This language
/// code should follow the conventions defined by the IETF in BCP47.
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: 0.6.6
version: 0.6.7

flutter:
plugin:
Expand Down
19 changes: 19 additions & 0 deletions packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ void main() {
);
});

test('unlink', () async {
final FirebaseUser user = await auth.unlink(
providerId: kMockProviderId,
);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'unlink',
arguments: <String, String>{
'app': auth.app.name,
'providerId': kMockProviderId,
},
),
],
);
});

test('signInWithFacebook', () async {
final FirebaseUser user = await auth.signInWithFacebook(
accessToken: kMockAccessToken,
Expand Down