How to add additional information to firebase.auth ()

How to add additional attributes of phone number and address to this data set? The Firebase documentation does not seem to report anything about this.

I implemented the login, registered and updated using firebase.auth()

Entrance:

 //Email Login firebase.auth().signInWithEmailAndPassword(email, password).then( ok => { console.log("Logged in User",ok.user); }, error => { console.log("email/pass sign in error", error); } ); 

Registration:

  //Sign Up firebase.auth().createUserWithEmailAndPassword(email, password).then( ok => { console.log("Register OK", ok); }, error => { console.log("Register error", error); } ) 

Update:

 //User Authentication firebase.auth().onAuthStateChanged(function(user) { if (user) { $scope.data=user; } else { // No user, Redirect to login page } }); //Save Function $scope.save=function(values){ $scope.data.updateProfile({ displayName: "Test User", email: " test@gmail.com ", /* phone: 123412341, address: "Temp Address",*/ photoURL: "www.example.com/profile/img.jpg" }).then(function() { // Update successful. }, function(error) { // An error happened. }); }; 
+6
source share
1 answer

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

You can do this by creating a link in Firebase to save all user profiles.

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

You can use onAuthStateChanged to detect when a user is logged in, and if you can use once() to retrieve user data

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

Hope this helps

+3
source

All Articles