cordova-plugin-facebook-connect / cordova-plugin-facebook-connect

Use the latest Facebook SDK in your Cordova and Ionic projects
Other
63 stars 90 forks source link

auth/account-exists-with-different-credential #64

Closed mayankkataria closed 3 years ago

mayankkataria commented 3 years ago

I'm facing a firebase error auth/account-exists-with-different-credential when I'm trying to sign in an already existing account(with different auth provider) with facebook. I know this question has been asked many times like here and here but all solutions works for web and I'm stuck with native plugins. I'm using Google Plus and Facebook Connect plugins to sign in on native platforms.

Code:

async continueWithGoogle() {
    try {
      const googleResponse = await this.googlePlus.login({ webClientId: environment.firebaseConfig.webClientId })
      const googleCredential = firebase.default.auth.GoogleAuthProvider.credential(googleResponse.idToken);
      const firebaseResponse = await firebase.default.auth().signInWithCredential(googleCredential);
      return firebaseResponse;
    } catch (error) {
        console.log('continue with google: ', error);
    }
  }

async continueWithFacebook() {
    try {
      const fbResponse = await this.facebook.login(['email']);
      const fbCredential = firebase.default.auth.FacebookAuthProvider.credential(fbResponse.authResponse.accessToken);
      const firebaseResponse = await firebase.default.auth().signInWithCredential(fbCredential);
      return firebaseResponse;
    } catch (error) {
      if (error.code === 'auth/account-exists-with-different-credential') {

        // What should I do here?

      }
      console.log('continue with fb: ', error);
    }
  }

Can I solve this error without using any web method like signInWithRedirect() or signInWithPopup()?

noahcooper commented 3 years ago

This question/error is not related to this plugin. The only part of this plugin involved in your code is retrieving an access token. The error you're referencing is an issue with Firebase itself.