首页 > 解决方案 > 链接帐户时如何从“auth/credential-already-in-use”错误中恢复

问题描述

遵循本指南: https ://firebase.google.com/docs/auth/web/account-linking 在我的网络应用程序中,我能够毫无问题地将两个帐户合并为一个,但是当我尝试在我的移动应用:

//action to recover from the 'auth/credential-already-in-use'

// Get reference to the currently signed-in user
const { currentUser } = firebase.auth();
var prevUser = currentUser;
// Sign in user with another account
firebase.auth().signInAndRetrieveDataWithCredential(linkError.credential).then((userCredential) => {
  console.log("Sign In Success", userCredential.user);
  var newUser = userCredential.user;
  // Merge prevUser and newUser data stored in Firebase.
  // Note: How you handle this is specific to your application

    // After data is migrated delete the duplicate user
    return newUser.delete().then(() => {
      // Link the OAuth Credential to original account
      return prevUser.linkAndRetrieveDataWithCredential(linkError.credential);
    }).then(() => {
      // Sign in with the newly linked credential
      return firebase.auth().signInAndRetrieveDataWithCredential(linkError.credential).then(() => {
        return dispatch(mergeAccountsCompleted())
      })
    });
  })

prevUser.linkAndRetrieveDataWithCredential 的执行失败并显示错误代码:'auth/no-current-user' 我找不到此错误的文档。所以我的问题是,当我想合并 react-native-firebase 中的现有帐户时,如何从 auth/credential-already-in-use 错误中恢复?

提前致谢 !

标签: react-native-firebase

解决方案


对此感到抱歉 - 由于我在 GitHub 上的问题评论中描述的困难,我们不得不放弃对错误对象的凭据的支持。

但是,我们有一些计划,最早将作为 v5.0.0 版本的一部分实施,或者最迟在 v5.1.0 版本中实施。

订阅上面链接的问题,我将在获得支持后更新并关闭它。


推荐阅读