【问题标题】:Firebase v3 updateProfile MethodFirebase v3 updateProfile 方法
【发布时间】:2016-11-28 07:20:39
【问题描述】:

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

我的理解是,这些属性是在用户登录时从第三方 oAuth 提供商 Google、Facebook、Twitter 或 GitHub 检索的。如果是基于密码的身份验证,则无法在管理控制台中使用或查看它们。

我可以为密码身份验证帐户存储此信息吗?如果可以,我可以通过管理控制台查看/管理此信息吗?

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

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

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案1】:

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

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

    合二为一,这里如何注册密码用户:

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

    【讨论】:

    • 是否有任何云功能触发配置文件更新?
    猜你喜欢
    • 2018-05-28
    • 1970-01-01
    • 2017-08-13
    • 2018-12-01
    • 2020-08-27
    • 1970-01-01
    • 2020-09-10
    • 2021-07-13
    • 1970-01-01
    相关资源
    最近更新 更多