【问题标题】:In Firebase, how do you update the displayName field of a user in Auth? [duplicate]在 Firebase 中,如何在 Auth 中更新用户的 displayName 字段? [复制]
【发布时间】:2017-01-29 03:23:45
【问题描述】:

我目前有一个创建用户帐户的功能。我也希望能够添加一个用户名字段,但我似乎无法弄清楚如何更新它。我注意到在 Google 控制台中,有一个 displayName 字段设置为 null。我不知道如何改变它。这就是我所拥有的:

function create(email, password, username) {
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
        $timeout(function() {
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorCode.toUpperCase() + ":" + errorMessage);
        })
    });
    firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
            $timeout(function() {
                console.log("Success! Account Created!");
                user.displayName = username; /* this doesn't work*/
            });
        } else {}
    });
}

【问题讨论】:

标签: javascript firebase firebase-realtime-database firebase-authentication


【解决方案1】:

firebase.auth.Auth 给你一个firebase.User。您应该查看可以在 User 上运行的方法:https://firebase.google.com/docs/reference/js/firebase.User

好像你在找updateProfile:https://firebase.google.com/docs/reference/js/firebase.User#updateProfile

【讨论】:

猜你喜欢
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 2016-11-23
  • 2020-05-31
相关资源
最近更新 更多