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

184
Vistas
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 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