【发布时间】: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