Home > Enterprise >  Why Firebase (onAuthStateChanged) does not see a Google signup user (with signInWithCredential)?
Why Firebase (onAuthStateChanged) does not see a Google signup user (with signInWithCredential)?

Time:08-13

So I followed this tutorial on how to sign in a user with rnfirebase and google signup. And it works fine. Here is the code:

const googleSignUp = async () => {
  // Get the users ID token
  const { idToken } = await GoogleSignin.signIn();

  // Create a Google credential with the token
  const googleCredential = auth.GoogleAuthProvider.credential(idToken);

  // Sign-in the user with the credential
  const user = auth().signInWithCredential(googleCredential);

  return { idToken, user };
};

(Let me note here, that the app has already a sign in with email and password way, with Firebase).

Then I realized that the user cannot change his name, email or delete his account. Looking deeper, I found out that the onAuthStateChanged(firebase.auth, async (user) => ... returns null for the user.

I've seen in some older answers that if you use Google sign up, you need to sign up the user with signInWithCredential, which I use, so this in not the issue.

Could it be a problem that for email/password sign in, I use code from Firebase web and not from rnfirebase? Although I already had a combination of those, using the push notifications from rnfirebase.

Can someone explain why I get this behavior, and how to fix it?

Thanks!

CodePudding user response:

If I understand correctly, you use both the react-native-firebase library (which wraps the native iOS and Android SDKs) and the JavaScript Web SDK for Firebase in your app.

If that is the case, both indeed have a separate sign-in state, and signing into one won't fire onAuthStateChanged listeners on the other.

You'll have to pick one SDK to authenticate with Firebase, and then use that for both providers.

  • Related