简体   繁体   English

为什么 Firebase (onAuthStateChanged) 看不到 Google 注册用户(使用 signInWithCredential)?

[英]Why Firebase (onAuthStateChanged) does not see a Google signup user (with signInWithCredential)?

So I followed this tutorial on how to sign in a user with rnfirebase and google signup.因此,我按照本教程介绍了如何使用rnfirebase和 google 注册来登录用户。 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). (让我在这里注意,该应用程序已经使用 email 和密码方式登录,使用 Firebase)。

Then I realized that the user cannot change his name, email or delete his account.然后我意识到用户不能更改他的名字 email 或删除他的帐户。 Looking deeper, I found out that the onAuthStateChanged(firebase.auth, async (user) =>... returns null for the user.深入研究,我发现onAuthStateChanged(firebase.auth, async (user) =>...为用户返回null

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.我在一些较旧的答案中看到,如果您使用 Google 注册,您需要使用我使用的signInWithCredential注册用户,所以这不是问题。

Could it be a problem that for email/password sign in, I use code from Firebase web and not from rnfirebase ?对于电子邮件/密码登录,我使用来自Firebase web而不是来自rnfirebase的代码会不会是一个问题? Although I already had a combination of those, using the push notifications from rnfirebase .虽然我已经有了这些的组合,但使用来自rnfirebase的推送通知。

Can someone explain why I get this behavior, and how to fix it?有人可以解释为什么我会出现这种行为,以及如何解决它吗?

Thanks!谢谢!

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 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.如果是这种情况,两者确实都有单独的登录 state,并且登录其中一个不会触发onAuthStateChanged侦听器。

You'll have to pick one SDK to authenticate with Firebase, and then use that for both providers.您必须选择一个 SDK 来通过 Firebase 进行身份验证,然后将其用于两个提供商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM