【问题标题】:Firebase Auth : During Auth not getting email from FirebaseUserFirebase 身份验证:在身份验证期间没有收到来自 FirebaseUser 的电子邮件
【发布时间】:2021-07-21 10:12:50
【问题描述】:

我已经在我的 Android 应用中使用 Google 实现了 Firebase 身份验证。当我尝试使用它登录时,我收到了来自FirebaseUser 类的电子邮件null

    private fun firebaseAuthWithGoogle(idToken: String) {
        val credential = GoogleAuthProvider.getCredential(idToken, null)
        auth.signInWithCredential(credential)
                .addOnCompleteListener(this) { task ->
                    if (task.isSuccessful) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success")
                        val user = auth.currentUser

                      if(user.email != null) {
                        sendUserDetailToServer()
                        updateUI(user)
                      }

                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.exception)
                        updateUI(null)
                    }
                }
    }

我可以获得其他详细信息,例如姓名、uid 等。

【问题讨论】:

    标签: android firebase kotlin firebase-authentication google-authentication


    【解决方案1】:

    您需要将其存储在数据库中 firebase auth not return 但您可以为此使用 admin sdk

    admin.auth().getUser(uid)
    admin.auth().getUserByEmail(email)
    admin.auth().getUserByPhoneNumber(phoneNumber)  
    

    【讨论】:

      【解决方案2】:

      为了能够使用与经过身份验证的用户对应的 Gmail 地址,您需要从 authResult 中获取它,而从 FirebaseUser 对象中获取它not,因为它尚未更新。因此,而不是以下代码行:

      val user = auth.currentUser
      

      请使用:

      val email = task.result?.user?.email
      

      【讨论】:

      • 你好 NarenderNishad!你有没有试过我上面的解决方案,它有效吗?
      猜你喜欢
      • 2021-10-05
      • 2018-02-10
      • 2022-08-07
      • 2023-03-18
      • 1970-01-01
      • 2017-08-10
      • 2021-03-26
      • 2021-12-08
      • 2018-10-09
      相关资源
      最近更新 更多