我正在尝试在我的应用程序中同时支持 facebook 和 google 登录。当用户登录发生在以下流程中时,
脸书 -> 谷歌 -> 脸书
我正面临错误auth/account-exists-with-different-credential
。我尝试使用此处描述的方法链接帐户。但是我没有收到文档描述的错误中的凭据或电子邮件数据。这是代码。
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))
打印["framesToPop", "code"]
如果我注释掉我尝试链接帐户的部分,则代码有效,用户以 Google 用户身份登录。
我在用着
"react-native-fbsdk": "^0.7.0",
"react-native-firebase": "^3.2.7"