Search code examples
react-nativefirebase-authenticationexpoapple-sign-in

expo apple sign in react native returning null values


I have sign in with apple implemented within my react native app. Some times it works some times it doesn't.

When it's not working it returns all null user values like this:

{
  "authorizationCode": "123456789omitted",
  "email": null,
  "fullName": Object {
    "familyName": null,
    "givenName": null,
    "middleName": null,
    "namePrefix": null,
    "nameSuffix": null,
    "nickname": null,
  },
  "identityToken": "987654321omitted",
  "realUserStatus": 1,
  "state": null,
  "user": "192837465omitted",
}

why would this be happening?

<AppleAuthentication.AppleAuthenticationButton
  buttonType={AppleAuthentication.AppleAuthenticationButtonType.SIGN_IN}
  buttonStyle={AppleAuthentication.AppleAuthenticationButtonStyle.BLACK}
  cornerRadius={5}
  style={{
    width: Constant.width * 0.92,
    height: 44,
  }}
  onPress={async () => {
    try {
      setAppleLoggingIn(true);
      const credential = await AppleAuthentication.signInAsync({
        requestedScopes: [
          AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
          AppleAuthentication.AppleAuthenticationScope.EMAIL,
        ],
      });
      // signed in
      onSignIn(credential);//signs in user via firebase
      setAppleLoggingIn(false);
    } catch (e) {
      if (e.code === "ERR_CANCELED") {
        // handle that the user canceled the sign-in flow
        setAppleLoggingIn(false);
        return {cancelled: true};
      } else {
        // handle other errors
        setAppleLoggingIn(false);
        return {error: true};
      }
    }
  }}
/>

I think it has something to do with this question but I never blocked the app from having access to my apple id...I always "accept" when it asks for permissions. Getting email id value null as response during apple-authentication


Solution

  • Apple Sign In only sends user info on the first sign in (sign up). After that, it's up to you to store those and reuse them when the user logs in again.