Add Extra Details on Firebase User Table

user3440236 picture user3440236 · Jun 25, 2015 · Viewed 44.6k times · Source

I'm working on a firebase+angularjs app and I'm using the simple email and password authentication and it's working properly.

I'm just wondering if I can add extra user data on the user table which is being used by firebase email+password auth, like I want to add billing info and other details concerning the user without creating extra node/table on firebase to store these extra data.

Answer

Frank van Puffelen picture Frank van Puffelen · Jun 25, 2015

Firebase stores the email/password users in a separate location, that you don't have direct access to. You cannot expand the data in this location.

Since many application developers want to access the user data in their application code, it is a common practice to store all users under a /users node inside the application database itself. The disadvantage is that you have to do this yourself. But the positive side of this is that you can store any extra information if you want.

See the Firebase guide on storing user data for sample code. From there:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.onAuth(function(authData) {
  if (authData && isNewUser) {
    // save the user's profile into Firebase so we can list users,
    // use them in Security and Firebase Rules, and show profiles
    ref.child("users").child(authData.uid).set({
      provider: authData.provider,
      name: getName(authData)
    });
  }
});