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

Commit

Permalink
Adding support for FirebaseUser.unlink(providerId)
Browse files Browse the repository at this point in the history
* Unlink an auth provider from a user account
  • Loading branch information
ko2ic committed Nov 20, 2018
1 parent eaa1388 commit a5d42fa
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## 0.6.3

* Add multi app support.
* Adding support for FirebaseUser.unlink(providerId)

## 0.6.2+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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 @@ -461,6 +463,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 @@ -220,6 +220,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
15 changes: 15 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FirebaseUserMetadata {
final Map<dynamic, dynamic> _data;

int get creationTimestamp => _data['creationTimestamp'];

int get lastSignInTimestamp => _data['lastSignInTimestamp'];
}

Expand Down Expand Up @@ -490,6 +491,20 @@ class FirebaseAuth {
return currentUser;
}

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
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 @@ -288,6 +288,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

0 comments on commit a5d42fa

Please sign in to comment.