Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase / AngularFire create user information

I'm creating a new user with AngularFire. But when I sign the user up I also ask for first name and last name and I add that info after registration.

$firebaseSimpleLogin(fbRef).$createUser($scope.signupData.email, $scope.signupData.password).then(function (user) {
  // Add additional information for current user
  $firebase(fbRef.child('users').child(user.id).child("name")).$set({
    first: $scope.signupData.first_name,
    last: $scope.signupData.last_name
  }).then(function () {
    $rootScope.user = user;
  });
});

The above code works, it creates node fin Firebase (users/user.id/ ...).

The problem

When I login with the new user I get the user default information: id, email, uid, etc. but no name. How can I associate that data automatically to the user?

like image 230
Angelin Avatar asked Feb 19 '14 11:02

Angelin


People also ask

How do I add a username to Firebase authentication?

You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.

Does Firebase Auth store user data?

Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).


1 Answers

You can't. Firebase hides the complexity of login management by storing the login details in its own datastore. This process knows nothing of your app's forge, which means it doesn't know if or where you're storing any additional user information. It returns the data that it does know about as a convenience (id, uid, email, md5_hash, provider, firebaseAuthToken).

It's up to your app to then take the [u]id and grab whatever app specific user information you need (such as first name, last name). For an Angular app, you'd want to have a UserProfile service which retrieves the data you're looking for once you get the authentication success broadcast.

Also, in your snippet, consider changing

.child(user.id) 

to

.child(user.uid) 

This will come in handy if you ever support Facebook/Twitter/Persona authentication later on. uid looks like "simplelogin:1" - it helps to avoid unlikely but possible id clashes across providers.

like image 100
Mike Pugh Avatar answered Oct 25 '22 14:10

Mike Pugh