Skip to content

credentialFromError returns NULL after upgrade to Alpha SDK #4389

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

Closed
awinogrodzki opened this issue Feb 2, 2021 · 2 comments · Fixed by #4394
Closed

credentialFromError returns NULL after upgrade to Alpha SDK #4389

awinogrodzki opened this issue Feb 2, 2021 · 2 comments · Fixed by #4394
Assignees

Comments

@awinogrodzki
Copy link

awinogrodzki commented Feb 2, 2021

[REQUIRED] Describe your environment

  • Operating System version: macOS Catalina 10.15.6
  • Browser version: Chrome 88.0.4324.96
  • Firebase SDK version: 0.900.11
  • Firebase Product: auth (auth, database, storage, etc)

[REQUIRED] Describe the problem

Steps to reproduce:

FacebookAuthProvider.credentialFromError returns null when trying to link anonymous user with an external provider, after moving to modular version of SDK.

The same applies to GoogleAuthProvider

Relevant Code:

The code with the previous version of SDK is working fine:

    const provider = new FacebookAuthProvider();
    provider.setCustomParameters({
      display: 'popup',
    });
    const firebaseUser = firebaseApp.auth().currentUser;

    if (firebaseUser && firebaseUser.isAnonymous) {
      try {
        const result = await firebaseUser.linkWithPopup(provider);
        return mapFirebaseResponseToUser(result.user!);
      } catch (error) {
        if (isCredentialAlreadyInUseError(error)) {
          await firebaseUser.delete();

          const result = await firebaseApp.auth().signInWithCredential(
            error.credential // <------ The credential here is correct
          );

          return mapFirebaseResponseToUser(result.user!);
        }

        throw error;
      }
    }

The code using Alpha SDK, null error credential:

    const provider = new FacebookAuthProvider();
    provider.setCustomParameters({
      display: 'popup',
    });
    const firebaseUser = getAuth(firebaseApp).currentUser;

    if (firebaseUser && firebaseUser.isAnonymous) {
      try {
        const result = await linkWithPopup(
          firebaseUser,
          provider, 
          browserPopupRedirectResolver
        );

        return mapFirebaseResponseToUser(result.user!);
      } catch (error) {
        if (isCredentialAlreadyInUseError(error)) {
          const credential = FacebookAuthProvider.credentialFromError(error); <!-- the credential here is null

          await firebaseUser.delete();

          const result = await signInWithCredential(
            getAuth(firebaseApp),
            credential!
          );
          return mapFirebaseResponseToUser(result.user!);
        }

        throw error;
      }
    }
@awinogrodzki awinogrodzki changed the title credentialFromError returns NULL on credentialFromError returns NULL after upgrade to Alpha SDK Feb 2, 2021
@sam-gc
Copy link
Contributor

sam-gc commented Feb 2, 2021

Hi @awinogrodzki, thanks for the super clear before/after samples! This is indeed a bug, thanks for raising it. I should have a PR out shortly

@sam-gc
Copy link
Contributor

sam-gc commented Feb 3, 2021

The linked PR fixes this issue and should be included in the next release. Thanks again for trying out the Alpha and for the detailed repro steps!

@firebase firebase locked and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants