Skip to content

Error merging two existing accounts #1385

@ygomezfinale

Description

@ygomezfinale

following this guide: https://firebase.google.com/docs/auth/web/account-linking In my web app I was able to merge two accounts into one with no problem, but when I try to do the same in my mobile app:

//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())
      })
    });
  })

The execution of prevUser.linkAndRetrieveDataWithCredential fails with the error code: 'auth/no-current-user' I couldn't find documentation for this error. So my question is, how can I recover from the auth/credential-already-in-use error when I want to merge the existing accounts in react-native-firebase ?

Thanks in advance !

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions