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

user.providerData is empty after update to v6 #917

Closed
henrik-d opened this issue Jan 19, 2022 · 3 comments · Fixed by firebase/firebase-js-sdk#5938
Closed

user.providerData is empty after update to v6 #917

henrik-d opened this issue Jan 19, 2022 · 3 comments · Fixed by firebase/firebase-js-sdk#5938

Comments

@henrik-d
Copy link

[REQUIRED] Describe your environment

  • Operating System version: MacOS Montery
  • Browser version: Chrome 97.0.4692.71
  • Firebase UI version: 6.0.0
  • Firebase SDK version: 9.6.3

[REQUIRED] Describe the problem

Since updating to firebaseui 6.0.0, after signing up or signing in the currentUser.providerData is empty. This problem did not occur in v4 and v5.

Relevant Code:

providerData is empty when using firebaseui for signIn:

import firebase from 'firebase/compat/app'
import 'firebase/compat/auth';
import * as firebaseui from 'firebaseui'
import 'firebaseui/dist/firebaseui.css'

const firebaseConfig = {...};
const app = firebase.initializeApp(firebaseConfig);
const auth = firebase.auth(app);

auth.onAuthStateChanged(user => {
    // Problem: authResult.user.providerData is empty after signin with firebaseui, ❌
    // but has one element when using auth.signInWithEmailAndPassword() directly ✅
    console.log("user signed in", user);
})

const signInSuccessWithAuthResult = (authResult: any, redirectUrl?: string) => {
    console.log("authResult", authResult); // Problem: authResult.user.providerData is empty! ❌
    auth.signOut();
    return false;
}

const ui = new firebaseui.auth.AuthUI(auth);
ui.start('#root', {
    signInOptions: [
        firebase.auth.EmailAuthProvider.PROVIDER_ID
    ],
    callbacks: {
        signInSuccessWithAuthResult,
    },
});

When using firebase directly, it works as expected:

auth.signInWithEmailAndPassword("[email protected]", "password").then(credential => {
    console.log("signInWithEmailAndPassword", credential); // credential.user.providerData.length === 1 ✅
    return auth.signOut();
})
@boldtrn
Copy link

boldtrn commented Jan 26, 2022

I can verify this, we are seeing the same issue.

When reloading the page, the providerData appears.

@boldtrn
Copy link

boldtrn commented Jan 26, 2022

As an intermediary fix, you can do the following:

if (fbUser.providerData && fbUser.providerData.length === 0) {
            console.debug('User data is not fully loaded, initiate reload');
            fbUser.reload().then(() => // update your UI here...);
}

@sam-gc
Copy link
Contributor

sam-gc commented Jan 26, 2022

Thanks for the report folks; the linked PR will fix the issue. You'll need to update your version of the Firebase JS SDK (i.e. not Firebase UI) to benefit from the fix once the PR is merged/released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants