0

I am building an app on android studio, I have connected the project to the Firebase (Real time database).

I have two types of accounts, business acc and regular acc, when the user logs in, based on his information (email, password), I want to know which page I want to send him to (the HomeActivity for business or for regulars).

So based on the structure of my database, I want to search for the email of a certain user and if I find it, I want to see, if it belongs to User Business or User Regular.

How can I do that by code in java? Thank you.

Database Structure :

enter image description here

Lalit Fauzdar
  • 5,953
  • 2
  • 26
  • 50

1 Answers1

0

With your current data structure, you'll need to run a separate query for regular users and for business users to find the node. That is because you can't search across two levels of nodes with a Firebase query. For more on that, see my answers:

For each node you'll need to do something like:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("User Business").orderByChild("email").equalTo("aamer@company.com")
query.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
            ...
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        throw databaseError.toException();
    }
}

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807