Skip to content

Adding support for FirebaseUser.unlink(providerId) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void onMethodCall(MethodCall call, Result result) {
case "linkWithFacebookCredential":
handleLinkWithFacebookCredential(call, result);
break;
case "unlink":
handleUnlink(call, result);
break;
case "updateProfile":
handleUpdateProfile(call, result);
break;
Expand Down Expand Up @@ -372,6 +375,16 @@ private void handleLinkWithFacebookCredential(MethodCall call, final Result resu
.addOnCompleteListener(new SignInCompleteListener(result));
}

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

private void handleSignInWithFacebook(MethodCall call, final Result result) {
@SuppressWarnings("unchecked")
Map<String, String> arguments = (Map<String, String>) call.arguments;
Expand Down
6 changes: 6 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
} else if ([@"unlink" isEqualToString:call.method]) {
NSString *providerId = call.arguments[@"providerId"];
[[FIRAuth auth].currentUser unlinkFromProvider:providerId
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
} else if ([@"updateProfile" isEqualToString:call.method]) {
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
if (call.arguments[@"displayName"]) {
Expand Down
13 changes: 13 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ class FirebaseAuth {
return currentUser;
}

Future<FirebaseUser> unlink({
@required String providerId,
}) async {
final Map<dynamic, dynamic> data = await channel.invokeMethod(
'unlink',
<String, String>{
'providerId': providerId,
},
);
final FirebaseUser currentUser = new FirebaseUser._(data);
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
20 changes: 19 additions & 1 deletion packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ void main() {
);
});

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

test('signInWithFacebook', () async {
final FirebaseUser user = await auth.signInWithFacebook(
accessToken: kMockAccessToken,
Expand Down Expand Up @@ -378,7 +396,7 @@ void main() {

test('updateEmail', () async {
final String updatedEmail = 'atestemail@gmail.com';
auth.updateEmail(email: updatedEmail);
await auth.updateEmail(email: updatedEmail);
expect(
log,
<Matcher>[
Expand Down