Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.6.3

* Added support for `linkWithPhoneNumber` in `FirebaseAuth`.
* Add multi app support.

## 0.6.2+1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public void onMethodCall(MethodCall call, Result result) {
case "getIdToken":
handleGetToken(call, result, getAuth(call));
break;
case "linkWithPhoneNumber":
handleLinkWithPhoneNumber(call, result);
break;
case "linkWithEmailAndPassword":
handleLinkWithEmailAndPassword(call, result, getAuth(call));
break;
Expand Down Expand Up @@ -257,6 +260,18 @@ private Map<String, Object> getVerifyPhoneNumberExceptionMap(FirebaseException e
return exceptionMap;
}

private void handleLinkWithPhoneNumber(MethodCall call, Result result) {
Map<String, String> arguments = (Map<String, String>) call.arguments;
String verificationId = arguments.get("verificationId");
String smsCode = arguments.get("smsCode");

PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, smsCode);
firebaseAuth
.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleLinkWithEmailAndPassword(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
@SuppressWarnings("unchecked")
Expand Down
12 changes: 12 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
completion:^(NSString *_Nullable token, NSError *_Nullable error) {
result(error != nil ? error.flutterError : token);
}];
} else if ([@"linkWithPhoneNumber" isEqualToString:call.method]) {
NSString *verificationId = call.arguments[@"verificationId"];
NSString *smsCode = call.arguments[@"smsCode"];

FIRPhoneAuthCredential *credential =
[[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationId
verificationCode:smsCode];

[[FIRAuth auth].currentUser linkWithCredential:credential
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
} else if ([@"linkWithEmailAndPassword" isEqualToString:call.method]) {
NSString *email = call.arguments[@"email"];
NSString *password = call.arguments[@"password"];
Expand Down
18 changes: 18 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@ class FirebaseAuth {
return currentUser;
}

/// Links phone number with current user and returns [Future<FirebaseUser>],
/// which will contain the phone number information.
/// This throws a [PlatformException] when the [smsCode] could not be validated or the [verificationId] is invalid.
Future<FirebaseUser> linkWithPhoneNumber({
@required String verificationId,
@required String smsCode,
}) async {
final Map<dynamic, dynamic> data = await channel.invokeMethod(
'linkWithPhoneNumber',
<String, String>{
'verificationId': verificationId,
'smsCode': smsCode,
},
);
final FirebaseUser currentUser = FirebaseUser._(data);
return currentUser;
}

/// Links email account with current user and returns [Future<FirebaseUser>]
/// basically current user with additional email information
///
Expand Down
11 changes: 11 additions & 0 deletions packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ void main() {
);
});

test('linkWithPhoneNumber', () async {
await auth.linkWithPhoneNumber(
verificationId: kMockVerificationId, smsCode: kMockSmsCode);
expect(log, <Matcher>[
isMethodCall('linkWithPhoneNumber', arguments: <String, String>{
'verificationId': kMockVerificationId,
'smsCode': kMockSmsCode,
})
]);
});

test('linkWithEmailAndPassword', () async {
final FirebaseUser user = await auth.linkWithEmailAndPassword(
email: kMockEmail,
Expand Down