Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!