I was trying to update data from my "user" database, I have tried it with the same documentation and with code from some forums, but with none of them it has worked for me, regarding the connection to the database, there is no problem, this would be my update code:
const ModalUpdateUser = ({ open, setOpen, userName, photoURL }) => {
const [fireCode, setFireCode] = useState()
const { email, uid } = useUser();
useEffect(async () => {
await db.collection('user').where('userId', "==", uid).onSnapshot(snap => {
setFireCode(snap.docs.map((doc) => ({
id: doc.id,
data: doc.data()
})))
})
}, [])
const onSubmit = async (data) => {
const newUserRef = db.collection('user').doc(fireCode[0].id);
const batch = db.batch();
firebase.auth().currentUser.updateProfile(data)
/*
FIRST FORM
.then(() => {
batch.update(newUserRef, {
email: email,
uid: uid,
displayName: data.displayName,
photoURL: data.photoURL
}) */
/*
SECOND FORM
db.collection('user').where('userId', "==", uid).update({
email: email,
uid: uid,
displayName: data.displayName,
photoURL: data.photoURL
}) */
/* }) */
.catch(error => console.log('problems :(', error))
};
}
in the useEffect, I am bringing the user information, mainly the id, to be able to use it in "newUseRef"
With the "FIRST FORM", it does not throw me any error, the whole process is carried out, but it is not updated in the database. With the "SECOND FORM", I get an "update is not a function" error, it is for this reason that I tried the "FIRST WAY".
Regarding the user information such as email and image, I bring them from redux.
the firebase version is "^8.8.1"