Android Firebase手机身份验证:如何检查首次登录?

时间:2020-05-28 18:31:12

标签: android firebase-realtime-database firebase-authentication

我要进行默认授权。

当用户首次通过电话号码登录该应用程序时,我希望在我的实时数据库中设置一些数据(wordPacks,状态等)。当用户注销并再次登录时,我希望用户查看其相关数据,而不是第一次登录时的默认数据。

我了解问题所在,但不知道如何解决。

private fun singInWithCredential(credential: PhoneAuthCredential) {
        val mAuth = FirebaseAuth.getInstance()
        mAuth.signInWithCredential(credential)
            .addOnCompleteListener(baseActivity) { task ->
                if (task.isSuccessful) {
                    val firebaseUserId = task.result?.user!!.uid
                    val map = hashMapOf(
                        "id" to firebaseUserId,
                        "username" to "Superhero",
                        "imageURL" to "url",
                        "wordPacks" to userDictionaryPacks,
                        "status" to "online"
                    )
                    val reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUserId)
                    reference.setValue(map).addOnCompleteListener { curTask ->
                        if (curTask.isSuccessful) {
                            if (isOnboardingViewed()) {
                                navigate(R.id.homeFragment)
                            } else {
                                navigate(VerificationFragmentDirections.actionVerificationFragmentToOnboardingFragment())
                            }
                        }
                    }
                } else {
                    otpSmsCode.text?.clear()
                    Snackbar.make(root, "Incorrect verification code. Try again.", Snackbar.LENGTH_LONG).show()
                }
            }

你能帮我吗?

更新:

这个问题不是重复的。

该链接包含有关Firebase Facebook登录的问题。

尽管两者都与Firebase登录有关,但此帖子实际上是使用用户手机号码登录的,而其他帖子的链接是关于用 facebook 登录。

两者的实现完全不同,根本无法回答这个问题。请取消重复该问题,以便予以解答。

0 个答案:

没有答案