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.