This code should create a user in firebase, but there was not a single entry there:
private fun enterCode() {
val code: String = binding.registerInputCode.text.toString();
val credential = PhoneAuthProvider.getCredential(id, code);
AUTH.signInWithCredential(credential).addOnCompleteListener { task ->
if (task.isSuccessful) {
val uid = AUTH.currentUser?.uid.toString();
val dateMap = mutableMapOf<String, Any>();
dateMap[CHILD_ID] = uid;
dateMap[CHILD_PHONE] = mPhoneNumber
dateMap[CHILD_USERNAME] = uid;
REF_DATABASE_ROOT.child(NODE_USER).child(uid).updateChildren(dateMap)
.addOnCompleteListener { task2 ->
if (task2.isSuccessful) {
showToast("Wellcome to the app")
(activity as RegisterActivity).replaceActivity(MainActivity())
} else
showToast(task2.exception?.message.toString())
}
} else
showToast(task.exception?.message.toString())
}
}
//another file with the authentication and the database reference
lateinit var AUTH: FirebaseAuth;
lateinit var REF_DATABASE_ROOT: DatabaseReference
const val NODE_USER = "users"
const val CHILD_ID = "id"
const val CHILD_PHONE = "phone"
const val CHILD_USERNAME = "username"
fun initFirebase(){
AUTH = FirebaseAuth.getInstance();
REF_DATABASE_ROOT = FirebaseDatabase.getInstance().reference
}
// my dependencies
// firebase
def firebaseVer = "22.0.0"
implementation "com.google.firebase:firebase-auth-ktx:$firebaseVer"
implementation "com.google.firebase:firebase-auth:$firebaseVer"
implementation 'com.google.firebase:firebase-firestore:24.6.1'
implementation 'com.google.firebase:firebase-database-ktx:20.2.2'
implementation 'com.google.firebase:firebase-database:20.2.2'
My Realtime Database this is the rules
'task' completed successfully, 'dateMap' was not null and filled with correct data. "REF_DATABASE_ROOT" had been correctly initialized. But I didn't get "task2" at all, nothing happened. What am I doing wrong and what should I do to fix the problem?