Issue
I created a user sign up and sign in form using firebase. After the user sign in, they are redirected to a profileform screen where they fill a form that is stored in Firestone, I want a situation where, if the user already filled a form he should be redirected to his dashboard else he should be redirected to profileform screen...
This is how I did it, I might be missing something `
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
});
if(doc.id != null){
//navigate to dashboard
}
else{
//navigate to profileform}
`
I got the profileform of a particular user, using doc.id
Solution
you should write your code in forEach like that
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
if(doc.id != null){
//navigate to dashboard
}
else{
//navigate to profileform}
});
Answered By - kadirfurkanguler
Answer Checked By - - Pedro (ReactFix Volunteer)