【问题标题】:Retrieve Google authenticated user data in Firebase在 Firebase 中检索经过 Google 身份验证的用户数据
【发布时间】:2018-01-27 01:54:09
【问题描述】:

在 Firebase 的 documentation 中声明

您在 Firebase 项目中创建一个新用户,方法是调用 createUserWithEmailAndPassword 方法或通过登录用户 首次使用联合身份提供商,例如 Google 登录 或 Facebook 登录。

我正在使用react-native-google-signin library 登录,经过一天的思考,它终于可以正常工作了。登录成功后,我可以看到登录的用户数据。

但在 Firebase 控制台中,在身份验证下,我没有看到添加了任何新用户。

当然,我想处理它的一种方法是看起来像

GoogleSignin.signIn().then(user => {
    // if the user doesn't already exist        
    firebase.auth()
        .createUserWithEmailAndPassword(user.email, randomPassowrd);
}) 

但这感觉像是一种解决方法,文档说您可以通过使用 google 登录在 Firebase 中创建一个新用户......那么为什么这不会自动发生?

这是我目前的实现,我认为这是最简单的方法,因为我说登录成功并且数据正在流入。

GoogleSignin
    .configure({
        iosClientId: IOS_CLIENT_ID
    })
    .then(() => {
         GoogleSignin
        .signIn()
        .then((user) => {
            console.log('user ->', user);
            dispatch(LoginSuccessAction(user))
        })
        .catch((err) => {
            dispatch(LoginFailAction())
        })
        .done();
    })
    .done();

【问题讨论】:

  • 如果您使用 Google(或任何其他提供商)为用户登录 Firebase 身份验证,他们将显示在 Firebase Authentication console 中。如果您的应用没有出现这种情况,请分享minimum code that reproduces the problem。
  • 我添加了代码示例
  • 您共享的代码不会让用户登录到 Firebase,因此他们确实不会出现在 Firebase 控制台中(他们也不会获得对 Firebase 服务的身份验证访问权限)。您错过了对firebase.auth().signInWithCredential(credential) 的呼叫,如下所示:firebase.google.com/docs/auth/web/…
  • @FrankvanPuffelen 好的,我太笨了,谢谢你的帮助,请将其发布为答案,以便我接受。
  • 很高兴听到你整理好了!整个 OAuth 流程总是有点混乱。

标签: firebase firebase-authentication google-signin


【解决方案1】:

如果您使用 Google(或任何其他提供商)为用户登录 Firebase 身份验证,他们将显示在 Firebase Authentication console 中。

您共享的代码不会让用户登录 Firebase,因此他们确实不会显示在 Firebase 控制台中(他们也不会获得对 Firebase 服务的经过身份验证的访问权限)。您错过了对 firebase.auth().signInWithCredential(credential) 的呼叫,如下所示:https://firebase.google.com/docs/auth/web/google-signin#advanced-handle-the-sign-in-flow-manually

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 2023-03-31
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2018-08-18
    相关资源
    最近更新 更多