Firebase v3 updateProfile 方法 [英] Firebase v3 updateProfile Method

查看:14
本文介绍了Firebase v3 updateProfile 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase v3 Auth 提供了一个 updateProfile 方法,该方法将 displayNamephotoURL 传递给 Firebase.

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

我的理解是,这些属性是在用户登录时从第 3 方 oAuth 提供商 Google、Facebook、Twitter 或 GitHub 检索的.对于基于密码的身份验证,它们在管理控制台中不可用或不可见.

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?

顺便说一句:我知道这可以存储在 users 节点/分支下的实时数据库中,但我正在询问是否将此信息存储在 Firebase 身份验证系统中.

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.

// 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.
});

推荐答案

.updateProfiledisplayNamephotoURL 属性存储在 Firebase Auth 中系统.因此,无需在实时数据库中的 users 节点下设置/获取这些内容.

.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.

您不会在 Firebase v3 身份验证控制台中看到这些属性.那样是不可见的.

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 + '.');
}

这篇关于Firebase v3 updateProfile 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆