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

useAuthState() and useIdToken() not logging the user in with Google #316

Open
jambudipa opened this issue Dec 27, 2023 · 0 comments
Open

Comments

@jambudipa
Copy link

jambudipa commented Dec 27, 2023

These two hooks will regularly, but not all the time, return an indeterminate state. That is, user is null; loading is false; and error is null.

This occurs when logging in with Google. It navigates successfully to the Google login page and no errors occur when redirecting back. loading switches from true to false, but user and error are both null.

This is an intermittent problem, happening seemingly according to no obvious pattern.

My particular use case is not important, since I can recreate it easily with the sample code, which I have here:

import { getAuth, signInWithEmailAndPassword, signOut } from 'firebase/auth';
import { useAuthState } from 'react-firebase-hooks/auth';
import { GoogleAuthProvider } from 'firebase/auth';

const auth = getAuth(firebaseApp)

const login = () => {
  signInWithRedirect(auth, new GoogleAuthProvider());
};
const logout = () => {
  signOut(auth)
};

const CurrentUser = () => {
  const [user, loading, error] = useAuthState(auth);

  if (loading) {
    return (
      <div>
        <p>Initialising User...</p>
      </div>
    );
  }
  if (error) {
    return (
      <div>
        <p>Error: {error}</p>
      </div>
    );
  }
  if (user) {
    return (
      <div>
        <p>Current User: {user.email}</p>
        <button onClick={logout}>Log out</button>
      </div>
    );
  }
  return <button onClick={login}>Log in</button>;
};

My code is not doing anything exotic. I have:

export const firebaseApp = initializeApp(firebaseConfig);

and have checked the firebaseConfig carefully for correctness.

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

1 participant