我正在学习 React,但是当我注册用户(使用 createUserWithEmailAndPassword)并尝试更新 displayName 属性时,我收到错误“ user1.updateProfile 不是函数”。
我该如何解决这个错误?
我的代码:
const register = async (e) => {
if (name.length == 0) {
alert("name cannot be empty");
} else {
const userWithEmailAndPassword = await createUserWithEmailAndPassword(auth, email, password)
.then((auth1) => {
const user1 = auth.currentUser;
user1.updateProfile({
displayName: name
});
})
.catch(error => alert(error.message))
console.log(userWithEmailAndPassword);
}
}
Run Code Online (Sandbox Code Playgroud)