updateProfile 不是函数 (Firebase)

updateProfile is not a function (Firebase)

我正在学习 React,但是当我注册用户(使用 createUserWithEmailAndPassword)并尝试更新显示名称时 属性 我收到错误消息“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);
        }
    }

使用Modular SDK时需要直接从Firebase Auth SDK导入updateProfile函数,如下图:

import { createUserWithEmailAndPassword, updateProfile } from "firebase/auth"

const register = async (e) => {
  if (name.length == 0) {
    alert("name cannot be empty");
  } else {
    const { user } = await createUserWithEmailAndPassword(auth, email, password)
    console.log(`User ${user.uid} created`)
    await updateProfile(user, {
      displayName: name
    });
    console.log("User profile updated")
  }
}