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] error.credential is always null, OAuthProvider.credentialFromError doesn't exist #11164

Closed
dsgriffin opened this issue Jun 20, 2023 · 20 comments · Fixed by #11683
Assignees
Labels
plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@dsgriffin
Copy link

dsgriffin commented Jun 20, 2023

Bug report

When attempting account linking in cases of email-already-in-use, I noticed that error.credential is now always null.

  catch (error) {
      if (error is FirebaseAuthException && error.code == 'email-already-in-use') {
        await auth.signInWithCredential(error.credential!); // error.credential is now always null
      }
  ...

I can see the error.credential prop has been removed from AuthError, but it still shown as existing in FirebaseAuthException in the firebase_auth package.

Here we are told by one of the Firebase team to replace usage of error.credential with the OAuthProvider.credentialFromError method.

However, credentialFromError doesn't exist on any of the OAuthProvider interfaces in firebase_auth.

Expected behavior

  1. OAuthProvider.credentialFromError should exist in firebase_auth
  2. FirebaseAuthException should remove credential and match the AuthError interface
  3. The docs should be updated to show this new correct method of retrieving an error object's credential.

Versions

firebase_auth: ^4.6.1

@dsgriffin dsgriffin added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] Missing new OAuthProvider.credentialFromError method (error.credential is always null) 🐛 [firebase_auth] Missing OAuthProvider.credentialFromError function (error.credential is always null) Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] Missing OAuthProvider.credentialFromError function (error.credential is always null) 🐛 [firebase_auth] Missing OAuthProvider.credentialFromError function impl (error.credential is always null) Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] Missing OAuthProvider.credentialFromError function impl (error.credential is always null) 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match Firebase v9 AuthError interface Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match Firebase v9 AuthError interface 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match new Firebase v9 AuthError interface Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match new Firebase v9 AuthError interface 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match new Firebase AuthError interface Jun 20, 2023
@dsgriffin dsgriffin changed the title 🐛 [firebase_auth] error.credential is always null, FirebaseAuthException doesn't match new Firebase AuthError interface 🐛 [firebase_auth] error.credential is always null, OAuthProvider.credentialFromError doesn't exist Jun 20, 2023
@darshankawar darshankawar added the triage Issue is currently being triaged. label Jun 21, 2023
@darshankawar
Copy link

Thanks for the report and analysis.

/cc @Lyokone for thoughts.

@darshankawar darshankawar added plugin: auth and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Jun 21, 2023
@Lyokone Lyokone self-assigned this Jul 10, 2023
@Lyokone
Copy link
Contributor

Lyokone commented Jul 10, 2023

Thanks for the report, I'm going to have a look to add this

@MirceaX2Mobile
Copy link

This is happening for me too. The credential property is always null

@SteadyAction
Copy link

same here

@SteadyAction
Copy link

@Lyokone @darshankawar any update?

@gazialankus
Copy link

Downgrading firebase_auth to 4.6.1 bypasses this as far as I can see. I do get the e-mail in the exception itself (e.email).

@MirceaX2Mobile
Copy link

Do we have any updates on this?

@kevinrobert3
Copy link

Any updates on this? Blocked on this

@MirceaX2Mobile
Copy link

I'm blocked on this and I can't update the rest of the libraries because of this.

@MirceaX2Mobile
Copy link

@russellwheatley do you know anything about a fix for this?

@MirceaX2Mobile
Copy link

@darshankawar do you know anything about a fix for this?

@russellwheatley
Copy link
Member

Is it erroring across all platforms or is this specific to web platform?

@MirceaX2Mobile
Copy link

MirceaX2Mobile commented Oct 6, 2023

@russellwheatley I encounter this on mobile platform while auth using SMS for example. If the user is already linked to that phone number I'm not getting the credential from the error to log in to the existing account.

switch (e.code) {
        case "provider-already-linked":
          final credential = e.credential;
          if (credential != null) {
            logInToExistingAccount(credential);
          }
          break;
        case "invalid-credential":
          showError(context.strings.invalidCredentials);
          break;
        case "credential-already-in-use":
          final credential = e.credential;
          if (credential != null) {
            logInToExistingAccount(credential);
          }
          break;
    }

e.credential is always null and user will be stuck.

The last working version of firebase auth is this one:
firebase_auth: 4.6.2

@kevinrobert3
Copy link

@russellwheatley Have encountered this on Apple sign-in and Facebook sign-in when linking providers. This for me is for both iOS and Android

@MirceaX2Mobile
Copy link

@russellwheatley @darshankawar
I saw that this fix is released. Now you get the credential, but when you try to use it

await auth.signInWithCredential(credential);

The sign in It's not working anymore. You get this

Screenshot 2023-10-20 at 18 31 14

@MirceaX2Mobile
Copy link

@russellwheatley @darshankawar
Can you look into this please? This is blocking my app for a really long time right now. I can't update the pubs like this :(

@russellwheatley
Copy link
Member

@MirceaX2Mobile - could you create a new issue as this is a different problem and could you also provide a repro. Thanks.

@MirceaX2Mobile
Copy link

@russellwheatley
I will do that. Or maybe is the same issue with this one?

If it is should I open a new one?
#11703

@russellwheatley
Copy link
Member

@MirceaX2Mobile - if you're experiencing this issue trying to link an anonymous account with an email account, then it is that issue.

@MirceaX2Mobile
Copy link

@MirceaX2Mobile In my case it's using Phone Authentication, but i think it has the same core logic. I will mention that there.

@firebase firebase locked and limited conversation to collaborators Nov 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
8 participants