Firebase: How to get email from sign in with apple on real device?

Viewed 1328

I'm implementing a sign in with apple, this is my code on apple button press

  onAppleButtonPress = async () => {
// performs login request
const appleAuthRequestResponse = await appleAuth.performRequest({
  requestedOperation: AppleAuthRequestOperation.LOGIN,
  requestedScopes: [
    AppleAuthRequestScope.EMAIL,
    AppleAuthRequestScope.FULL_NAME,
  ],
});

// Ensure Apple returned a user identityToken
if (!appleAuthRequestResponse.identityToken) {
  console.log('no token');
  throw 'Apple Sign-In failed - no identify token returned';
}

// Create a Firebase credential from the response
const {identityToken, nonce} = appleAuthRequestResponse;
const appleCredential = firebaseAuth.AppleAuthProvider.credential(
  identityToken,
  nonce,
);


//I WANT TO GET THE EMAIL HERE TO USE CHECK IT FROM FIREBASE IF EMAIL ALREADY EXISTS BY THIS CODE

firebaseAuth()
        .fetchSignInMethodsForEmail(appleAuthRequestResponse.email)
        .then(providers => {

});

}

It works on the simulator, but on real device the email is null. Anyone who can help?

1 Answers

Apple only returns the full name and email on the first login, it will return null on the succeeding login so you need to save those data.

T receive these again, go to your device settings; Settings > Apple ID, iCloud, iTunes & App Store > Password & Security > Apps Using Your Apple ID, tap on your app and tap Stop Using Apple ID. You can now sign-in again and you'll receive the full name and `email.

Source here.

Related