I'm trying to implement an apple signing with firebase using the '@invertase/react-native-apple-authentication' library.
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?
