代码之家  ›  专栏  ›  技术社区  ›  Murad Axundov

我的功能只有一小部分有效。怎样(科特林)

  •  0
  • Murad Axundov  · 技术社区  · 1 年前

    我的代码一直运行到(Log.d(TAG,“signInWithCredential:success”),它在Logcat中给出了“signInWithCredential:success“输出,而不是其他日志。这是怎么可能的,因为我的Log.d(“tag”,“User:$User”)//记录这里的用户值只放在第一个日志的下面一行。这是我的代码:

      private fun signInWithPhoneAuthCredential(credential: PhoneAuthCredential) {
                mAuth.signInWithCredential(credential)
                    .addOnCompleteListener(this) { task ->
                        val user = task.result?.user // Declare and initialize the user variable
        
                        if (task.isSuccessful) {
                            // Sign in success, update UI with the signed-in user's information
                            Log.d(TAG, "signInWithCredential:success")
        
                            Log.d("tag", "User: $user") // Log the user value here
        
                            if (user != null) {
                                Log.d("tag", "User is not null")
                                val userId: String = user.uid
                                val users = Users(userId, "", "${user.phoneNumber}", "", "", "", "", "", "", "")
        
                                firestore.collection("Users").document("UserInfo").collection(userId)
                                    .add(users)
                                    .addOnSuccessListener {
                                        Log.d("tag", "Database operation success")
                                        startActivity(Intent(applicationContext, SetUserInfoActivity::class.java))
                                        progressDialog.dismiss()
                                    }
                                    .addOnFailureListener { e ->
                                        Log.d("tag", "Database operation failed: ${e.message}")
                                        progressDialog.dismiss()
        
                                    }
                            } else {
                                Log.d("tag", "User is null")
                                Toast.makeText(applicationContext, "Something went wrong", Toast.LENGTH_SHORT).show()
                            }
        
                        } else {
                            // Sign in failed, display a message and update the UI
                            progressDialog.dismiss()
                            Log.w(TAG, "signInWithCredential:failure", task.exception)
                            if (task.exception is FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                            }
                            // Update UI
                        }
                    }
            }
    
    0 回复  |  直到 1 年前