我的功能只有一小部分有效。如何? (科特林)

问题描述 投票:0回答:0

我的代码一直运行到 ( Log.d(TAG, "signInWithCredential:success") ) 它在 Logcat 中给出了 "signInWithCredential:success" 输出,但没有在其他日志中输出。这怎么可能因为我的 Log.d("tag", "User: $user") // Log the user value here is placed only line down of the first log .这是我的代码:

  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
                    }
                }
        }
android kotlin logcat
© www.soinside.com 2019 - 2024. All rights reserved.