1

I'm starting on kotlin and Firebase

I'm using the AuthUI to login users, and would like to store some additional information (Profile Picture, Adresse, etc).

I have a collection of "Users" to store that information, as well as the User Id.

I'm trying to search if given a User Id, there's no information about it (That would happen after the user signs up using the AuthUI) and in that case, I'll call a new Activity to welcome the user to the app and ask for the additional information.

I can't find a way to search for it, using kotlin...

Thank you in advance

2 Answers2

0

Just try to fetch data with the id. If the query comes up with nothing, the data doesn't exist.

oittaa
  • 599
  • 3
  • 16
0

i've used several code i found online. Currently i'm doing this:

fun checkIfUserExists(userId : String) {
val rootRef = FirebaseDatabase.getInstance().reference
val userNameRef = rootRef.child("users").child(userId)
val eventListener: ValueEventListener = object : ValueEventListener {
    override fun onDataChange(dataSnapshot: DataSnapshot) {
        if (!dataSnapshot.exists()) {
            //create new user
        }
    }

    override fun onCancelled(databaseError: DatabaseError) {

    }
}
userNameRef.addListenerForSingleValueEvent(eventListener)}

The code runs but it nevers executes the onDataChange...

My db is currently emptyenter image description here