How to add extra fields to Firebase auth? Age & Gender

In general, after sign up, you can create a node tree for user like picture. Then, you can get the info with user key that can get by calling FirebaseUser. I hope it helps. If you have any questions, let me know.an example


Sorry about the delay, but I was looking for how to store considerably larger custom data - which isn't possible, however here's how I do it.

Store small amounts of extra data inside the displayName (Javascript).

result.user.updateProfile({
    displayName: gender + '|' + sex + '|' + username
})
.then(function () {
    console.log(`Profile updated.`);

To retrieve the data, simply split up the displayName (Node.js):

        return admin.auth().getUser(uid)
    })
    .then(userRecord => {
        displayName = userRecord.getDisplayName();

        parts = String(user.displayName).split('|');

        gender = parts[0];
        sex = parts[1];
        username = parts[2];

When you are using Firebase authentication with user and password, the only data that you can get after authentication is that data that you get from FirebaseUser object. As you probably see, there also a couple of methods that can help you get the data easier, like: getEmail(), getDisplayName(), getPhotoUrl() and so on.

Unfortunately, you cannot add additional data like age and gender to the FirebaseUser object. If you want to add additional data, you need to create a model class for your user and then store it in your Firebase database.

You model class should look like this:

public class User {
    String name, gender, emailAddress;
    int age;

    public User(String name, String gender, String emailAddress, int age) {
        this.name = name;
        this.gender = gender;
        this.emailAddress = emailAddress;
        this.age = age;
    }

    public String getName() {return name;}
    public void setName(String name) {this.name = name;}

    public String getGender() {return gender;}
    public void setGender(String gender) {this.gender = gender;}

    public String getEmailAddress() {return emailAddress;}
    public void setEmailAddress(String emailAddress) {this.emailAddress = emailAddress;}

    public int getAge() {return age;}
    public void setAge(int age) {this.age = age;}
}