Search code examples
androidfirebasefirebasesimpleloginfirebase-authentication

Understanding createUser function of firebase(specifically android library)


So I have the following code that I got from the firebase documentation (which I implemented in my app already and it's working fine):

    Firebase ref = new Firebase("https://myapp.firebaseio.com");
    ref.createUser("[email protected]", "correcthorsebatterystaple", new Firebase.ValueResultHandler<Map<String, Object>>() {
       @Override
       public void onSuccess(Map<String, Object> result) {
          System.out.println("Successfully created user account with uid: " + result.get("uid"));
       }
       @Override
       public void onError(FirebaseError firebaseError) {
        // there was an error
       }
    });

after I create a user it prints on the console its uid. However, when I enter in my myapp.firebaseio.com there is nothing there.. So I have some questions:

  1. Where does firebase stores this new user created?
  2. How can I add some custom fields? (this functions uses just email and password) i.e Username

So, What I have tried to do was inside the onSuccess() I used ref.push() some values to myapp.firebaseio.com but then .. how can I check if the users uid created by the createUser() is the same as the one who I pushed? (the id's are differente!)

I hope my text it's clear, if isn't asked and I can try to explain again!

Thanks a bunch!


Solution

  • User information is not stored inside your Firebase database. For anonymous and OAuth users, no information is stored anywhere. The information for email+password users is kept in a separate database that you don't have access to. The email+password users are visible in the Login & Auth tab of your dashboard of course, just not in your database.

    If you want to store user information in your own Firebase database, you have to store it there yourself when you create or authenticate the user. There is a section on storing user data in the Firebase documentation that shows how to do this.

    One advantage of having to store the information yourself, is that you get to determine exactly what is and what isn't stored.