'Is there any way to make my firebase database accept details even when it is not throwing a direct error
I am trying to Register a user and save their email and name to the firebase database but it is not working. When I try registering it always tell me encountered some error. please how do I fix it ?. I have tried to fix it by myself ,still it is not working. Below are my codes.
override fun onCreate(savedInstanceState: Bundle?) {
binding = ActivitySignupBinding.inflate(layoutInflater)
super.onCreate(savedInstanceState)
setContentView(binding.root)
supportActionBar?.hide()
mAuth = FirebaseAuth.getInstance()
binding.signupbutton.setOnClickListener {
val email = binding.signupmail.text.toString().trim()
val password = binding.signuppassword.text.toString().trim()
val name = binding.signupname.text.toString().trim()
if (email.isEmpty()){
binding.signupmail.error = "Email is Empty"
binding.signupmail.requestFocus()
return@setOnClickListener
}
when {
name.isEmpty() -> {
binding.signupname.error = "Name is Empty"
binding.signupname.requestFocus()
return@setOnClickListener
}
password.isEmpty() -> {
binding.signuppassword.error= "Enter password"
binding.signuppassword.requestFocus()
return@setOnClickListener
}
else -> {
mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this){task->
if (task.isSuccessful) {
saveUserInfo(name,email,mAuth.currentUser?.uid!!)
} else Toast.makeText(this , "Some Error occurred", Toast.LENGTH_LONG).show()
}
}
}
}
}
private fun saveUserInfo(name: String, email: String, uid: String) {
mDbRef =FirebaseDatabase.getInstance().getReference()
mDbRef.child("user").child(uid).setValue(User(name,email, uid))
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
