When trying to access the currently authenticated user for Apple Log In, I am getting null.
I am using react-native-apple-authentication for apple authentication as recommended.
I have this working for both email and facebook authentication, but after trying to get it on the app store i received feedback saying all apps need to have apple authentication since April 2020 if using another third party authentication service.
The user is indeed logged in and authenticated (According to firebase console and success callbacks) But firebase cannot detect it for some reason in my app.
Here is how I am logging the user in
async onAppleButtonPress() {
// Start the sign-in request
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: AppleAuthRequestOperation.LOGIN,
requestedScopes: [AppleAuthRequestScope.EMAIL, AppleAuthRequestScope.FULL_NAME],
});
// 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 { identityToken, nonce } = appleAuthRequestResponse;
const appleCredential = RNFirebase.auth.AppleAuthProvider.credential(identityToken, nonce);
// Sign the user in with the credential
return RNFirebase.auth().signInWithCredential(appleCredential).then(() => {
this.props.loginUserApple(appleCredential);
});
}
Here is my action creators to complete the sign in:
export const loginUserApple = credential => {
// I am receiving credential, but nothing for user
console.log(credential);
return dispatch => {
if (credential) {
dispatch({type: LOGIN_USER_START});
loginUserSuccessApple(dispatch, credential);
} else {
loginUserFail(dispatch);
}
};
};
const loginUserSuccessApple = (dispatch, user) => {
firebase.auth().onAuthStateChanged(authedUser => {
if (authedUser) {
//THIS SHOULD BE RETURNING THE UID OF THE APPLE AUTHED USER
const {currentUser} = firebase.auth();
const uid = currentUser.uid;
firebase
.database()
.ref(`/users/${currentUser.uid}/uid`)
.set(uid)
.then(() => {
console.log('success, navigate to check auth')
console.log(authedUser._user)
dispatch({
type: LOGIN_USER_SUCCESS,
payload: authedUser._user,
});
Actions.checkAuth();
});
return;
} else {
alert('Something went wrong.')
}
});
};