React-native-apple-authentication: Apple auth email is null (data apple signin and firebase email null)

Created on 19 Jan 2021  路  17Comments  路  Source: invertase/react-native-apple-authentication

  • react-native: 0.63.3
  • @intervase/react-native-apple-authentication: 2.1.0
  • react-native-firebase: 5.6.0

TESTED

  • Tested on device real iPhone 12 pro max (iOS 14.3)
  • Xcode 12.3

EMAIL is NULL

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

    // get current authentication state for user
    const credentialState = await appleAuth.getCredentialStateForUser(
      appleAuthRequestResponse.user,
    );
    const dataDecode = jwtDecode(appleAuthRequestResponse.identityToken);
    console.log('DATA DECODEE ',dataDecode);
    console.log('USER LOG APPLEEEE ', appleAuthRequestResponse);

    // use credentialState response to ensure the user is authenticated
    const { identityToken, nonce } = appleAuthRequestResponse;
    if (identityToken) {
      // e.g. sign in with Firebase Auth using `nonce` & `identityToken`
      const appleCredential = firebaseFather.auth.AppleAuthProvider.credential(
        identityToken,
        nonce,
      );
      const userCredential = await authFirebase.signInWithCredential(appleCredential);
      Flux.dispatchEvent(LOGIN_APPLE);
      // console.log('userCredential with Applee ', userCredential);
      console.log('Firebase authenticated via Apple, UID: ', userCredential.user.uid);
      if (credentialState === appleAuth.State.AUTHORIZED) {
        console.log(' insidee of AUTHORIZED success ');
        // user is authenticated
      }
    } else {
      const error = {
        message: 'There was an error starting with sign in apple.',
      };
      Flux.dispatchEvent(LOGIN_APPLE_ERROR, error);
    }
  } catch (error) {
    console.log('logs of Error ', error);
    if (error.code === appleAuth.Error.CANCELED) {
      error.message = 'Sign in Apple was canceled';
      Flux.dispatchEvent(LOGIN_APPLE_ERROR, error);
    } else {
      error.message = 'There was an error starting with sign in apple';
      Flux.dispatchEvent(LOGIN_APPLE_ERROR, error);
    }
  }
};

LOGS

Screen Shot 2021-01-19 at 10 27 40 AM

Firebase

The user is saved without email, so I cannot continue the registration or linking of users

Screen Shot 2021-01-19 at 10 28 03 AM

Most helpful comment

Apple is give the data only one time. try another account or you should try after delete login log. In your iPhone, setting-Apple ID - password&security - Apps using Apple ID - App name - stop using Apple ID. Then api will give to you new date form.

All 17 comments

@mikehardy hi, can you help me?

If you can reproduce with the example included here, sure

@mikehardy this is the token that we are getting. Is not the first login, but it seems that doesn't bring the email

eyJraWQiOiI4NkQ4OEtmIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLm9rcm9vIiwiZXhwIjoxNjExMTU3NjcwLCJpYXQiOjE2MTEwNzEyNzAsInN1YiI6IjAwMTU4OC5kNThkODQzMDFlNzg0NTkxOTEwNDBhY2I5NDdkZWZlZi4wMzA5Iiwibm9uY2UiOiJjZmYxOTAyOGIxMjRlMzY3MTNjZGI0NDYzMWNhYTRkMWVjODAxNjRmYTk2YTJlN2E2ZjljMjhjY2U1NjY0YWIwIiwiY19oYXNoIjoicFVuY2FESWk5WkRERjNURDJxSUh4USIsImF1dGhfdGltZSI6MTYxMTA3MTI3MCwibm9uY2Vfc3VwcG9ydGVkIjp0cnVlfQ.N1PJjCy8KnqzQWTiWEVZXZHrHZuvBDIX5FvgZEljfo5fE8UPoZtx0HfUBmJoUzgeWWANT4iY9iZIGoD9QnBbUsi1qgm_L8dmRNEWNb8P17lOAiDeOMUEfYMoVgwOsFhXfA4Tm-ZgssxmcoOonUpqTwvubT26gpkFArzeAr4QxitB3Het2AnFyTzLNx9sKQbzbP8HHyBeuZpvPGeIkUmOODdShbj6duS_2qvEJLxhJHNOeYoDW9Tjj_Pcx2i0FQJl_ZM7qnJn8qH4nvnMQ65VyNWDqaUxLlIB4HtGSks_hF9xEZ7et4cu7brGbOYvpyZudpP3qNP-hM0biaIopCU4xA

Screen Shot 2021-01-19 at 10 50 18 AM
Screen Shot 2021-01-19 at 10 50 18 AM (2)

yes @mikehardy @alacret

the onAppleButtonPress function is what I call when I login in the real device, but it never brings me the email and I also tried to use a jwtDecode (appleAuthRequestResponse.identityToken); and here the email doesn't arrive either

but this information arrives to firebase auth but firebase doesn't return the email either and in fact the user is inserted but without email in firebase

How did it go when you reproduce with the example?

well, but appleAuthRequestResponse never returns my email and neither does identityToken contain email @mikehardy

so firebase doesn't recognize the email from the parameters that passed it to the function firebase.auth.AppleAuthProvider.credential(identityToken, nonce); and so I can't continue the process

So you are telling me, if I integrate this module with react-native-firebase right now and do an apple signing (for instance on an ios13 simulator) that a new user won't work because email is not present? If you answer that this is correct I will verify this next time I'm near a Mac.

exactly but in my case I tried it from a real device, the iPhone 12 pro max, not from a simulator because you clearly indicate that in a simulator gives error @mikehardy

I clearly indicated ios13 works great. Ios14 fails. Okay I will test, maybe Apple changed something

I clearly indicated ios13 works great. Ios14 fails. Okay I will test, maybe Apple changed something

@mifi Thanks let us know if we can do anything to help

@mikehardy ahm ok ok yes, my iPhone is iOS 14.3 with that was the one I tested, thanks let us know if we can do anything to help

_Hello, same issue in iOS 14.3,email is null, and I followed the steps of @mikehardy to revoke apple._

The solution was to wait a short time, approximately 2 to 5 min after removing the apple sign in account in settings.

The example app works perfectly for me on ios13 emulator, watch the console output.
I get my email in there, and the identityToken contains it as well.
I'll check on my phone later but this has a lower priority for me now.

People reporting problems: check out the repository, yarn && cd example && yarn && cd ios && pod install, then from example dir yarn start in one terminal and create an emulator profile named iPhone 11 ios13 that is (you guessed it) an iPhone 11 but configured for iOS 13.7 (as of this typing?), then run yarn run:ios13

It should work.

We have had lots of users with issues getting emails before. Not one has been a problem with the module yet, so the burden of proof is on reporters here to reproduce this with the example watching the console in the simulator and with a real device plugged in / example launched from xcode

Apple is give the data only one time. try another account or you should try after delete login log. In your iPhone, setting-Apple ID - password&security - Apps using Apple ID - App name - stop using Apple ID. Then api will give to you new date form.

I did what @ChanghyeonYoon indicated and the login worked, I do not understand what happened, I remember that the last time I logged in was on an iPhone 8 months ago in the same app with the same apple id and then I logged in recently with the new iPhone and that's when I got the error. thank you very much! @mikehardy @ChanghyeonYoon

@ marquina-abreu if you once try to register with apple id and you allow to share your email id and name, things go fine if you do not cancel from the pop up, once you cancel the process name and email goes null all the time until somehow as @ ChanghyeonYoon stated you do not reset it so if there any method to revoke/reset if we cancel then it can work fine.

Was this page helpful?
0 / 5 - 0 ratings