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

188
Visualizações
trying to save firebase id in redux-toolkit (possible problem with async/await)

I was doing a login with firebase and I have an error, to be clearer this is my code:

    const handleLogin = async () => {
        await db.collection('user').where("email", '==', inputs.email).onSnapshot(sna => {
            sna.docs.map(current => {
                console.log(current.id)
                setNewId(current.id)
            })
        })
        await signInWithEmailAndPassword(authentification, inputs.email, inputs.password)
            .then(({ user }) => dispatch(userLogin({
                name: user.displayName,
                email: user.email,
                photo: user.photoURL,
                id: newId // this is not saved
            })))
            .then(() => navigate('/'))
            .catch(() => setError(true))
        console.log('end')
    }

what I do with the first block of code is to consult my database (firebase) for the user to be able to save his id with setNewId, with the second block I am performing the authentication of the user by email and password and then I redirect him to another page.

Almost everything is saved correctly in redux toolkit except the id. The request to my 'user' database is successful because in the console.log() it shows the user's id, but I don't understand why the id is not saved in my context (redux-toolkit).

It may be a problem with the promises or with async/await, but I can't find a solution.

about 4 years ago · Juan Pablo Isaza
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