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

[Firefox] Flash of unstyled content when sending/verifying phone otp #1075

Open
docentdr opened this issue Mar 13, 2024 · 2 comments
Open

[Firefox] Flash of unstyled content when sending/verifying phone otp #1075

docentdr opened this issue Mar 13, 2024 · 2 comments

Comments

@docentdr
Copy link

[REQUIRED] Describe your environment

  • Operating System version: macOS 12.5
  • Browser version: Firefox 123.0.1
  • Firebase UI version: 6.1.0

[REQUIRED] Describe the problem

Steps to reproduce:

I am only using phone sign-in method. After I click on "verify" button and after I click on "Continue" button, a white modal appears. From my investigation, the first modal (that displays after verify) is for saying "Code Sent" - I was not able to identify what the modal is for after I click on Continue.

firebaseui-firefox-fouc

Relevant Code:

import React, { useEffect, useState } from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import * as firebaseui from "firebaseui";
import "firebaseui/dist/firebaseui.css";
import { useNavigate } from "react-router-dom";
import { checkUserExists } from "../services/api";

const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID,
  measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
};

if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
  firebase
    .auth()
    .setPersistence(firebase.auth.Auth.Persistence.LOCAL)
    .catch((error) => {
      console.log(error);
    });
} else {
  firebase.app();
}

const Auth = () => {
  const [ui, setUi] = useState(null);
  const navigate = useNavigate();

  useEffect(() => {
    if (!ui) {
      firebase
        .auth()
        .setPersistence(firebase.auth.Auth.Persistence.LOCAL)
        .then(() => {
          const uiInstance =
            firebaseui.auth.AuthUI.getInstance() ||
            new firebaseui.auth.AuthUI(firebase.auth());
          setUi(uiInstance);
        })
        .catch((error) => {
          console.log(error);
        });
    }

    const uiConfig = {
      signInOptions: [
        {
          provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
        },
      ],
      callbacks: {
        signInSuccessWithAuthResult: (authResult) => {
          handleSignInSuccess(authResult.user);
          return false;
        },
      },
    };

    if (ui) {
      ui.start("#firebaseui-auth-container", uiConfig);
    }

    return () => {
      if (ui) {
        ui.delete().then(() => setUi(null));
      }
    };
  }, [ui, navigate]);

  const handleSignInSuccess = async (user) => {
    try {
      const currentUser = await checkUserExists();
      if (currentUser.exists) {
        navigate("/admin");
      } else {
        navigate("/signup", { state: { phoneNumber: user.phoneNumber } });
      }
    } catch (error) {
      console.error("An error occurred:", error);
    }
  };

  return (
    <>
      <div id="firebaseui-auth-container"></div>
    </>
  );
};

export default Auth;
@jhuleatt
Copy link
Collaborator

Hi @docentdr, does this occur in your browser if you run the demo?

If not, I wonder if this is a React issue. You may need to declare a ref for the FirebaseUI container with useRef to avoid React cleaning up and re-creating FirebaseUI

@docentdr
Copy link
Author

Hey @jhuleatt - yes the behavior occurs when I run the demo application as well

demo-firefox

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

2 participants