I'm trying to support both facebook and google login in my app. When user login takes place in the following flow,
Facebook -> Google -> Facebook
I'm facing the error auth/account-exists-with-different-credential. I've tried to link the accounts using the method described here. But I'm not receiving credential or email data in the error as described by the docs. Here is the code.
const facebookLogin = async () => {
try {
const result = await (LoginManager.logInWithReadPermissions(['public_profile', 'email']));
if (result.isCancelled) {
throw new Error('User cancelled request'); // Handle this however fits the flow of your app
}
console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`);
// get the access token
const data = await AccessToken.getCurrentAccessToken();
if (!data) {
throw new Error('Something went wrong obtaining the users access token'); // Handle this however fits the flow of your app
}
// create a new firebase credential with the token
const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);
// login with credential
const currentUser = await firebase.auth().signInAndRetrieveDataWithCredential(credential);
return currentUser
} catch (error) {
if(error.code == 'auth/account-exists-with-different-credential') {
console.log(Object.keys(error))
const credential = error.credential
const googleUser = await googleLogin()
const linkedUser = await googleUser.linkAndRetrieveDataWithCredential(credential)
return linkedUser
}
console.log(e)
}
}
console.log(Object.keys(error)) prints ["framesToPop", "code"]
The code works if I comment out the part where I try to link the accounts, the user is signed-in as a Google user.
I'm using
"react-native-fbsdk": "^0.7.0",
"react-native-firebase": "^3.2.7"