I am trying to add "Apple Sign In" to my Flutter iOS app using the apple_sign_in package.
The code is mostly working. My problem is that the call to _firebaseAuth.signInWithCredential(credential) is creating a firebase account that has a null identifier (please see screenshot below).
One weird thing about this is that when the user selects the option to share their email address when signing up, result.credential.email contains the user's email address after the call to AppleSignIn.performRequests(). So I'm really puzzled as to why the user's email is not being used as the identifier when the account is created in Firebase.
Future<FirebaseUser> signInWithApple() async {
final AuthorizationResult result = await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
switch (result.status) {
case AuthorizationStatus.authorized:
final AppleIdCredential appleIdCredential = result.credential;
OAuthProvider oAuthProvider =
new OAuthProvider(providerId: "apple.com");
final AuthCredential credential = oAuthProvider.getCredential(
idToken: String.fromCharCodes(appleIdCredential.identityToken),
accessToken: String.fromCharCodes(
appleIdCredential.authorizationCode),
);
await _firebaseAuth.signInWithCredential(credential);
return _firebaseAuth.currentUser();
break;
case AuthorizationStatus.error:
print('Sign in failed: ${result.error.localizedDescription}');
break;
case AuthorizationStatus.cancelled:
print('User cancelled');
break;
}
return null;
}
