firebase / firebaseui-web

FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
https://firebase.google.com/
Apache License 2.0
4.58k stars 1.06k forks source link

FirebaseUI doesn't work properly in chrome mobile randomly: 20s latency onAuthStateChanged event #1053

Open EmilioNicolas opened 11 months ago

EmilioNicolas commented 11 months ago

Describe your environment

Describe the problem

If using my firebaseUI implementation, randomly it appears the error code: TypeError: u[v] is not a function

Then it is not after 20 seconds that I receive auth.onAuthStateChanged event

Why could this be happening?

Thanks in advance for your help!

sbrett commented 10 months ago

Also experiencing this issue, I have tried several combinations of the sign in flows and settings but have been unable to get this working as expected on mobile web.

jhuleatt commented 10 months ago

Sorry to hear that this is happening. I tried to reproduce the issue on the demo app in Chrome on my Pixel 5 with email sign-in, sign in with Google, and phone sign-in, and wasn't able to reproduce the issue.

Can you please share which mobile OS you're using, which sign-in method you're trying, and if possible a minimal code sample? That should help us figure this out.

EmilioNicolas commented 10 months ago

Ey! I solved it.

This changes worked for me:

Removal of HTML script tags: image

Added imports in JS: image

Sorry about the image format!

jhuleatt commented 10 months ago

@EmilioNicolas thanks for the update, and glad that fixed it! Just to help us chase down this issue - did you switch to the npm install of the Firebase SDK now that you've removed the gstatic script tags? I'm wondering if the bug may specifically apply to the combination of FirebaseUI 6.1.0 and Firebase 10.0.0 served from gstatic.

EmilioNicolas commented 10 months ago

Hi! Yep, I switched to npm and then all good so it seems you are right about the buggy combo

sbrett commented 10 months ago

Experiencing this on firebase 10.6.0 and firebaseui 6.1.0 via NPM. Strangely enough it only seems to occur on the mobile web view (including chrome device toolbar). The callback seems to take 20+ seconds, or sometimes not work at all. Sometimes just clicking the "Sign in with Google" button results in a 10+ second load time. TypeError: u[v] is not a function is often in the console.

Things I have tried:

Here is a minimal version of my code:

export const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "",
    measurementId: ""
};

// Initialize Firebase
export const app = initializeApp(firebaseConfig);

export const firebaseAuthUiConfig = {
    callbacks: {
        signInSuccessWithAuthResult: function (authResult: any, redirectUrl: any) {
            return true;
        },
        uiShown: function () {
        }
    },
    signInSuccessUrl: getConfig().AUTH_REDIRECT_URL,
    signInOptions: [
        {
            provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
            clientId: "",

        },
        {
            provider: firebase.auth.EmailAuthProvider.PROVIDER_ID
        },
    ],
};

useEffect(() => {
  const unsubscribe = onAuthStateChanged(getAuth(app), (fbUser) => {   
    if(!fbUser){
      navigate("/login");
    }
    setUser(!!user);
  });

  return () => {
    unsubscribe();
  };
}, [user, setUser, navigate]);

const handleClick = () => {
    signOut(getAuth())
}

export const FbAuth = () => {

    useEffect(() => {
        const ui =
            firebaseui.auth.AuthUI.getInstance() ||
            new firebaseui.auth.AuthUI(getAuth(app));
        ui.start("#firebaseui-auth-container", firebaseAuthUiConfig);
    }, []);

    return (
        <div>
            <button onClick={handleClick}>Sign out</button>
            <div id="firebaseui-auth-container"></div>
        </div>
    );
};
sbrett commented 9 months ago

Any update here? I am still experiencing this issue and have been trying for weeks to fix it with no luck.