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

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

Open
EmilioNicolas opened this issue Nov 23, 2023 · 7 comments

Comments

@EmilioNicolas
Copy link

EmilioNicolas commented Nov 23, 2023

Describe your environment

  • Operating System version: Mac OS 13.4
  • Browser version: chrome 119 (on mobile compatibility)
  • Firebase UI version: latest
  • Firebase SDK version: latest

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
Copy link

sbrett commented Nov 29, 2023

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

jhuleatt commented Dec 4, 2023

@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
Copy link
Author

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

@sbrett
Copy link

sbrett commented Dec 4, 2023

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:

  • Ensuring client ID is correct
  • Ensuring authorized domains in firebase console is correct
  • Ensuring my list of authorized redirect URIs in the cloud console is correct
  • Ensuring my list of authorized javascript origins in the cloud console is correct
  • Trying both the firebaseapp.com and web.app domains as the value for the authDomain key in my config, as per the redirect best practices
  • Trying various redirect URLs including __/auth/handler
  • I have tried a couple of different combinations of versions of both packages but have not strayed too far from the latest

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
Copy link

sbrett commented Jan 17, 2024

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

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

No branches or pull requests

3 participants