【问题标题】:Firebase Authentication current user nullFirebase 身份验证当前用户 null
【发布时间】:2020-06-18 16:56:28
【问题描述】:

由于某种原因,FirebaseAuth.getInstance().currentUser 为 null,即使此时用户必须登录。

我已经按照官方文档实现了身份验证并按预期登录,但登录后获取当前用户为空。

这是我的身份验证方式:

override fun onStart() {
        super.onStart()

        //user already signed in if non-null
        auth.currentUser?.let {
            gotToMainActivity()
        }

        // Check for existing Google Sign-In account, if the user is already signed in
        // the GoogleSignInAccount will be non-null.
        GoogleSignIn.getLastSignedInAccount(this)?.let {
            gotToMainActivity()
        }
    }

我正在使用 Activity 记录用户,但尝试在片段中获取登录用户。我不知道这是否会导致问题。

【问题讨论】:

  • 如果你在 google 上搜索你的问题的标题,你会发现 Stack Overflow 上总是有人问这个问题。
  • 你试过currentUser= FirebaseAuth.instance().currentUser

标签: android firebase firebase-authentication


【解决方案1】:

我发现了我的问题。我的应用支持 Firebase 身份验证和 Google 登录。 使用 Google 登录时,FirebaseAuth.getInstance().currentUser 为空。

所以我必须检查 Firebase 或 GoogleSignIn 并使用非 null 中的任何一个。

【讨论】:

    猜你喜欢
    • 2021-07-31
    • 1970-01-01
    • 2021-08-23
    • 2020-03-12
    • 2018-06-03
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    相关资源
    最近更新 更多