3

I am getting the error 'auth/account-exists-with-different-credential' by using firebase.auth().signInWithCredential(credential).catch(error => ....

As suggested at :Firebase JS API auth - account-exists-with-different-credential I am catching the error and then do this to resolve the exception:

firebase.auth().fetchSignInMethodsForEmail(error.email)
   .then(providers => {
      firebase.auth().signInWithCredential(credential)
         .then(user => {
            user.linkWithCredential(error.credential)
         })
   })
   ...

The problem is that my error object does not contain email or credential properties. It only contains : code, framesToPop, nativeStackAndroid and userInfo (which is null).

This is my code:

const result = await LoginManager.logInWithPermissions(['public_profile', 'email']);

const data = await AccessToken.getCurrentAccessToken();

if (data) {
    const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);

    firebase.auth().signInWithCredential(credential).catch(error => {
      if (errorCode === 'auth/account-exists-with-different-credential') {
        firebase.auth().fetchSignInMethodsForEmail(error.email)
           .then(providers => {
                firebase.auth().signInWithCredential(credential)
                  .then(user => {
                    user.linkWithCredential(error.credential)
                  })
            }).catch(error => log(error))
      } else {
        console.error(error);
      }
    });
}
...

Why is that happening?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Tal
  • 613
  • 1
  • 7
  • 19
  • 1
    Did you find a solution to this? If so, can you please answer your own question? I'm having the exact same problem but can't find many similar questions on the web. – Lehar001 Dec 03 '19 at 21:39

0 Answers0