Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
How to call updateProfile() after creating User

I am trying to set the .displayName property of a user, right after it is created.

The Problem: The user needs some time to get created, so it would not work to use .updateProfile() right after calling .createUserWithEmailAndPassword(). So how can I eventually update the .displayName right after the creation?

Right now I am trying this way:

export function signup(currentUser, email, password) {
    createUserWithEmailAndPassword(auth, email, password)
    updateProfile(currentUser, {displayName : "some name"})   
}

When I am calling the function I use this function for the value of currentUser

export function useAuth() {
    const [ currentUser, setCurrentUser ] = useState();

    useEffect(() => {
        const unsub = onAuthStateChanged(auth, user => setCurrentUser(user));
        return unsub; // Cleaning Function
    }, [])

    return currentUser;
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Both the createUserWithEmailAndPassword() and updateProfile() methods are asynchronous and return a Promise. Therefore you either need to chain the Promises or use async/await as mentioned by Scott in his comment.

1/ Chain the Promises

export function signup(currentUser, email, password) {
    createUserWithEmailAndPassword(auth, email, password)
    .then(userCredential => {
       updateProfile(userCredential.user, {displayName : "some name"})   
    })
}

2/ Use async/await

export async function signup(currentUser, email, password) {
    const userCredential = await createUserWithEmailAndPassword(auth, email, password);
    await updateProfile(userCredential.user, {displayName : "some name"})   
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to call updateProfile(currentUser, {displayName : currentUser.displayName}) after currentUser have been updated by the useAuth hook

useEffect(() =>{
   if ('userName' in currentUser && currentUser.userName !== '') {
    updateProfile(currentUser, {displayName : currentUser.userName})  
   }
}, [currentUser])

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda