Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda