credentialFromError returns NULL after upgrade to Alpha SDK

[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;
      }
    }

1 possible answer(s) on “credentialFromError returns NULL after upgrade to Alpha SDK

  1. 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!