capawesome-team / capacitor-firebase

⚡️ Firebase plugins for Capacitor. Supports Android, iOS and the Web.
https://capawesome.io/plugins/firebase/
Apache License 2.0
409 stars 104 forks source link

bug: Facebook login giving error if email address is already registered with another provider #729

Closed aliexalter closed 2 months ago

aliexalter commented 2 months ago

Plugin(s)

Version

6.1.0

Platform(s)

Current behavior

If user is logged in before with Google Sign In the firebase creates a user. After if user login using facebook sign I, it gives following error. Error: An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address. code: account-exists-with-different-credential

I am using try - catch to fetch the errors as below

async signInWithFacebook() {
    try {
      const result = await FirebaseAuthentication.signInWithFacebook();
      console.log("My FB result",result);
      this.router.navigate(['/tabs']);
    } catch (error:any) {
      console.log(error);
      console.log("My FB Error",error);
      this.showErrorToast(error);
    }
  }

Problem here is under error I cannot get code, where code is only shown in plugin error (that is i think native level).

Expected behavior

It should allow to get error.code so by checking the code the user auth is linked to another provider.

If there is any other solution to this problem please guide.

Reproduction

just create new ionic app and add firebase authentication with login buttons as signIn google and signIn facebook

Steps to reproduce

Create an ionic angular capacitor app Install Capacitor FirebaseAuthentication plugin Create login page add two buttons (facebook and google sign in) first sign in using google then sign in with facebook.

Other information

No response

Capacitor doctor

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

Installed Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

[success] iOS looking great! 👌 [success] Android looking great! 👌

Before submitting

aliexalter commented 2 months ago
Screenshot 2024-09-26 at 8 44 44 PM
robingenz commented 2 months ago
Screenshot 2024-09-26 at 8 44 44 PM

I'm not sure if I understand your problem. As you can see in your screenshot, the code is returned from the plugin. Just access it using "error.code".

aliexalter commented 2 months ago

In log where it says My FB error it's showing as string not an object how can I access error.code

Dexus commented 2 months ago

In log where it says My FB error it's showing as string not an object how can I access error.code

You have catched the error now use in the catch the error.code and gotcha ;)

robingenz commented 2 months ago

I close this issue as the code is already provided by the plugin.