Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_auth]: account-exists-with-different-credential exception does not include email and credential so the plugin does not allow to link the accounts #17160

Open
1 task done
ohhyungkwon opened this issue Mar 2, 2025 · 4 comments · May be fixed by #17180
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: auth type: bug Something isn't working

Comments

@ohhyungkwon
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Auth

Which platforms are affected?

iOS

Description

User already has an account with email provider and try to sign in with Microsoft. The account-exists-with-different-credential exception rises but the exception does not have an email and credential property. According to the document, the exception is supposed to have the properties so user can link the existing account with Microsoft account. It works with android but does not with iOS.

Reproducing the issue

  1. Sign up with email provider. => Make sure there is an account in firebase console.
  2. Sign in with Microsoft with same email using below code.
final provider = OAuthProvider('microsoft.com');
// or final provider = MicrosoftAuthProvider();

provider.setCustomParameters({'prompt': 'select_account'});

UserCredential userCredential = await FirebaseAuth.instance.signInWithProvider(provider);

Expected behavior:
account-exists-with-different-credential rises and it has email and credential property.

Actual behavior:
account-exists-with-different-credential rises and it does not have email and credential property.

Firebase Core version

3.10.1

Flutter Version

3.22.3

Relevant Log Output

Flutter dependencies

...
firebase_core: ^3.10.1
firebase_auth: ^5.4.1
firebase_crashlytics: ^4.3.1
google_sign_in: ^6.2.2
...

Additional context and comments

No response

@ohhyungkwon ohhyungkwon added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Mar 2, 2025
@SelaseKay SelaseKay added plugin: auth platform: ios Issues / PRs which are specifically for iOS. labels Mar 3, 2025
@MichaelVerdon
Copy link
Contributor

Hey there, we were able to reproduce this issue and will be investigating it further.

@MichaelVerdon
Copy link
Contributor

Having a closer look, we believe it is coming from native ios-sdk as none of this error handling seems to occur on FlutterFire. There is a similar issue that was reported on FlutterFire here #13268 but then we marked is as blocked: sdk. Here is the issue on the native-sdk: firebase/firebase-ios-sdk#13671. I would advise you to open a new issue on the native-ios-sdk.

@SelaseKay SelaseKay removed the Needs Attention This issue needs maintainer attention. label Mar 5, 2025
@ohhyungkwon
Copy link
Author

But I can make this work with native ios-sdk. Below code is for Swift and works correctly.

Auth.auth().signIn(with: credential) { authResult, error in
    
    // login success
    if let authResult = authResult {
     ...
    } else if let error = error as? NSError {
        // duplicated account
        if error.code == AuthErrorCode.accountExistsWithDifferentCredential.rawValue,
           let email = error.userInfo[AuthErrorUserInfoEmailKey],
           let pending = error.userInfo[AuthErrorUserInfoUpdatedCredentialKey] as? OAuthCredential {

           // link account
           ...
        } else if error.code == AuthErrorCode.secondFactorRequired.rawValue,

I believe there is a miscommunication between native iOS-sdk and flutterfire when they are using methodChannel.

@MichaelVerdon
Copy link
Contributor

Hey there, thanks alot for the information we will keep investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: auth type: bug Something isn't working
Projects
None yet
3 participants