Reputation: 63
I saw this question was asked multiple times and I reviewed all of them before posting the question. I have a kotlin activity that is used to register a user. This has two activity, one is to use FirebaseAuth to create the new user, on successful completion, I am storing the user information expcet password in FirebaseDatabase. When I run the code the application I can see the user is getting created in the Firebase Auth console. But the user collection is not created in the database.
Unfortunately there are no errors or exceptions in the logcat either.
private fun saveUserInfo(nickname: String, email: String, progressDialog: ProgressDialog) {
val currentUserID = FirebaseAuth.getInstance().currentUser!!.uid
val database = FirebaseDatabase.getInstance()
val usersRef = database.getReference("users")
val userMap = HashMap<String, Any>()
userMap["uid"] = currentUserID
userMap["nickname"] = nickname
userMap["email"] = email
usersRef.child(currentUserID).setValue(userMap)
.addOnCompleteListener {
if (it.isSuccessful){
progressDialog.dismiss()
Toast.makeText(this, "User created successfully", Toast.LENGTH_LONG)
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
finish()
} else {
progressDialog.dismiss()
FirebaseAuth.getInstance().signOut()
val message = it.exception!!.toString()
Toast.makeText(this, "Error: " + message, Toast.LENGTH_LONG)
}
}
.addOnFailureListener {
progressDialog.dismiss()
FirebaseAuth.getInstance().signOut()
val message = it.message.toString()
Toast.makeText(this, "Error: " + message, Toast.LENGTH_LONG)
}
}
I have the rules setup as
{
"rules": {
".read": true,
".write": true
}
}
Since the user id is getting created in Firebase Auth I know the connection is working. What could that I might be missing here?
I tried
val database = FirebaseDatabase.getInstance()
val myRef = database.getReference("message")
myRef.push().setValue("Hello, World!")
.addOnFailureListener {
Log.d("TAG", it.message.toString())
}
and that also did not work. I did use andrioid studio assistant and made sure database was connected.
Upvotes: 1
Views: 402
Reputation: 63
After six hours of debugging and reading through all the suggestions. I came across an answer where the solution as rebooting the laptop. I did not take that answer seriously but that did the fix. To me, it looks like there is a bug in firebase database connectivity that was released to able to reconnect after rebooting.
Upvotes: 1