3

I am making a small app in php and I am using firebase as a backend server for managing, authenticating users. I have a signup form with more than two fields, email and password(name, tel-number, location etc) but in the firebase documentation(code below), we can only register a user with email and password. So, my question is how I can save other information of user and later how I would retrieve that information?

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});
koceeng
  • 2,169
  • 3
  • 16
  • 37
StealthTrails
  • 2,281
  • 8
  • 43
  • 67

1 Answers1

5

You can create a reference in firebase to keep all the users profiles.

users: {
  "userID1": {
    "name":"user 1",
    "gender": "male" 
  },
  "userID2": {
    "name":"user 2",
    "gender": "female" 
  }
}

You can use onAuthStateChanged to detect when the user is logged in

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

And then if the user is logged in you can use this to retrieve user's data

firebaseRef.child('users').child(user.uid).once('value', callback)

As far as I you have to manage the users profiles by yourself if you want to have more fields than the default user provided by Firebase

Hope it helps

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73