Firebase: Error (auth/argument-error). Using Apple Sign In With React Native Expo

117 views Asked by At

I'm building the Apple Sign In using React Native in an Expo project. I'd like to link the user to a firebase user however, I am getting the above error.

  1. I have my Apple Sign In Key within the keys section on the Apple Developer Account.

  2. I have added the "expo-apple-authentication" plugin to my app.json as per the below

    {
      ...
      "plugins": [
          [
            "expo-apple-authentication",
            [
              "@stripe/stripe-react-native",
              {
                "merchantIdentifier": "XXXXXXXXXXXXXXXXXXXX",
                "enableGooglePay": false
              }
            ]
          ]
        ]
    }
    

Here's the code

const createUserWithApple = async () => {
    try {
      const credential = await AppleAuthentication.signInAsync({
        requestedScopes: [
          AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
          AppleAuthentication.AppleAuthenticationScope.EMAIL,
        ],
      });
      const { identityToken } = credential;
      if (identityToken) {
        console.log("ID TOKEN:", identityToken); // I AM GETTING TOKEN HERE YAY!
        const provider = new OAuthProvider("apple.com");
            provider.addScope("email");
            provider.addScope("name");
            const providerCredential = provider.credential({ identityToken });
            const result = await signInWithCredential(
              FIREBASE_AUTH,
              providerCredential
            );
            console.log("GOT RESULT:", result);
          }
        } catch (error) {
          console.log("CAUGHT ERROR:", error);
        }
      };

I'm not sure if I have my Service ID correct in the Firebase Console though. It appears to be my {MY_TEAM_ID.MY_BUNDLE_IDENTIFIER}

enter image description here

1

There are 1 answers

0
David Henry On

SOLVED

Change:

const providerCredential = provider.credential({ identityToken });

To:

const providerCredential = provider.credential({ idToken: identityToken });