【问题标题】:Firebase Authentication returns NULL for getCurrentUser() even though there's a user in Firebase Console即使 Firebase 控制台中有用户,Firebase 身份验证也会为 getCurrentUser() 返回 NULL
【发布时间】:2021-06-03 08:32:52
【问题描述】:

当用户在注册片段中输入 username、email 和 password 时,他会被转发到一个验证片段,我在其中向他发送了电子邮件验证,他会一直停留在该屏幕上,直到他点击来自电子邮件,然后他被转发到个人资料片段。

当用户在验证片段上时,他可以在点击我发送的电子邮件中的链接之前返回到注册片段。在这种情况下,我从 onStart() 调用一个函数来从 Firebase 中删除他的数据:

private fun deleteUnverifiedAccount() {
        val firebaseAuthentication = FirebaseAuth.getInstance()
        if (firebaseAuthentication.currentUser == null) {
            shortToast("empty")
        }
        if (firebaseAuthentication.currentUser != null) {
            if (!firebaseAuthentication.currentUser.isEmailVerified) {
                val user = firebaseAuthentication.currentUser
                user.delete()
                    .addOnCompleteListener {
                        shortToast("deleted")
                    }
            }
        }
    }

问题来了:

  1. 此函数成功从 Firebase 身份验证中删除用户
  2. 但是当用户第二次尝试注册时,他的数据再次被保存到 Firebase 身份验证中。
  3. 如果此时他再次返回注册片段而不验证他的电子邮件,那么他的数据不会从 Firebase 身份验证中删除。
  4. 当调用 deleteUnverifiedAccount() 函数时,它会显示 currentUser == null,即使他在 Firebase 身份验证中显然不是 null。

【问题讨论】:

    标签: android firebase android-fragments


    【解决方案1】:

    首先,我没有尝试从 firebase 中删除任何用户,但我刚刚搜索了一些内容,我发现此链接 https://www.javatpoint.com/firebase-realtime-database-update-and-delete 此链接将对您有所帮助,因为我认为您尝试删除用户而不是用户数据的代码问题. 你的语法是这样的

    myFirebase.child(current user's id).remove value 
    

    你能在 user.delete() 之前试试这个吗?我希望它能工作

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 2021-08-23
      • 2021-09-27
      • 2018-10-30
      • 2017-12-10
      • 2016-12-13
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      相关资源
      最近更新 更多