react-native-firebase

时间:2018-03-08 17:48:27

标签: firebase react-native-android react-native-firebase

我正在尝试在我的应用中支持facebook和google登录。当用户登录发生在以下流程中时,

Facebook - > Google - >实

我正面临错误auth/account-exists-with-different-credential。我尝试使用here描述的方法链接帐户。但是我没有收到文档中描述的错误中的凭据或电子邮件数据。这是代码。

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"

0 个答案:

没有答案