0
votes

I'm trying to implement an apple signing with firebase using the '@invertase/react-native-apple-authentication' library.

enter image description here

The problem appears when executing the signInWithCredential method. Firebase returns the error: Error: [auth/invalid-credential] The supplied auth credential is malformed or has expired

The code

export async function loginWithApple() {
    // Start the sign-in request
    try {
        console.log('TRY');
        const appleAuthRequestResponse = await appleAuth.performRequest({
            requestedOperation: AppleAuthRequestOperation.LOGIN,
            requestedScopes: [
                AppleAuthRequestScope.EMAIL,
                AppleAuthRequestScope.FULL_NAME,
            ],
        });

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

        // Create a Firebase credential from the response
        const {
            nonce,
            identityToken,
        } = appleAuthRequestResponse;

        if (identityToken) {
            console.log(nonce, identityToken);

            // Sign the user in with the credential
            const appleCredential = auth.AppleAuthProvider.credential(
                identityToken,
                nonce,
            );
            auth()
                .signInWithCredential(appleCredential)
                .then((response) => console.log('loginWithApple', response))
                .catch((error) => console.log('222222', error));
            console.warn(
                `Firebase authenticated via Apple, UID: ${userCredential.user.uid}`,
            );
        } else {
            console.log('loginWithApple no token - failed sign-in');
        }
    } catch (error) {
        ...
    }
}

Could someone please help me?

1
Hi! Hope you are having a good day. Are you able to pinpoint us where do we need to correctly put in the services ID in places? Thank you - 4 Leave Cover

1 Answers

1
votes

So... After days of investigating the issue was found. That was the wrong Services ID at the firebase settings.