Estoy aprendiendo React, pero cuando registro un usuario (usando createUserWithEmailAndPassword) e intento actualizar la propiedad displayName, aparece el error " user1.updateProfile no es una función ".
¿Cómo puedo solucionar este error?
Mi código:
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); } }La función updateProfile debe importarse directamente desde Firebase Auth SDK cuando se usa Modular SDK, como se muestra a continuación:
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") } }