Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase v3 updateProfile Method

Firebase v3 Auth offers an updateProfile method that passes displayName and photoURL to Firebase.

My understanding is that these properties are retrieved from 3rd party oAuth providers Google, Facebook, Twitter, or GitHub upon user login. In case of Password based Auth, they are not available or viewable from the Admin console.

Can I store this info for password Auth accounts, and if so can I view/administer this info via the Admin console?

BTW: I know this could be stored in the Realtime Database under a users node/branch but I am asking about storing this info in the Firebase Auth system.

enter image description here

// Updates the user attributes:
user.updateProfile({
  displayName: "Jane Q. User",
  photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(function() {
  // Profile updated successfully!
  // "Jane Q. User"
  var displayName = user.displayName;
  // "https://example.com/jane-q-user/profile.jpg"
  var photoURL = user.photoURL;
}, function(error) {
  // An error happened.
});

// Passing a null value will delete the current attribute's value, but not
// passing a property won't change the current attribute's value:
// Let's say we're using the same user than before, after the update.
user.updateProfile({photoURL: null}).then(function() {
  // Profile updated successfully!
  // "Jane Q. User", hasn't changed.
  var displayName = user.displayName;
  // Now, this is null.
  var photoURL = user.photoURL;
}, function(error) {
  // An error happened.
});
like image 903
Ronnie Royston Avatar asked Jul 25 '16 03:07

Ronnie Royston


1 Answers

.updateProfile stores the displayName and photoURL properties in the Firebase Auth system. Therefore, there is no need to set/get this stuff under a users node in your Realtime Database.

You will not see these properties in the Firebase v3 Auth Console. It's not viewable that way.

Rolled into one, here how to register a password user:

registerPasswordUser(email,displayName,password,photoURL){
  var user = null;
  //nullify empty arguments
  for (var i = 0; i < arguments.length; i++) {
    arguments[i] = arguments[i] ? arguments[i] : null;
  }

  firebase.auth().createUserWithEmailAndPassword(email, password)
  .then(function () {
    user = firebase.auth().currentUser;
    user.sendEmailVerification();
  })
  .then(function () {
    user.updateProfile({
      displayName: displayName,
      photoURL: photoURL
    });
  })
  .catch(function(error) {
    console.log(error.message);
  });
  console.log('Validation link was sent to ' + email + '.');
}
like image 103
Ronnie Royston Avatar answered Sep 22 '22 23:09

Ronnie Royston