根据Firebase网站上的JS Auth文档,它只显示了如何获取displayName以及如何更新displayName。所以我尝试更新它。但这有点不合逻辑,因为你怎么能在不创建它的情况下更新它。
所以我的问题是,如何在注册期间设置用户的显示名称?
function createUser(email, password) {
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function (error) {
error.message.replace(".", "");
alert(error.message + " (" + error.code + ")");
document.getElementById("password").value = "";
});
if (firebase.auth().currentUser != null) {
firebase.auth().currentUser.updateProfile({
displayName: document.getElementById("name").value
}).then(function () {
console.log("Updated");
}, function (error) {
console.log("Error happened");
});
}
}
我已经试过了,但它被证明是行不通的......
真诚的, 法鲁克
最佳答案
您必须链接请求:
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(result) {
return result.user.updateProfile({
displayName: document.getElementById("name").value
})
}).catch(function(error) {
console.log(error);
});`
关于javascript - 如何设置 Firebase 用户的显示名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40389946/