I have a react app which basically wants to give some special permission if the logged in user is an admin. For this i have a table in the db where I store all administrator emails.
I have an UseEffect which I use to verify the current logged in user if it is available in the admin user db.
useEffect(() => {
const getUsers = async () => {
const data = await getDocs(adminUsersCollectionRef);
console.log(data);
const user = data.docs.find((x) => x.data().email === currentUser.email);
console.log(user.data());
if (user && user.data()) {
console.log("inside if")
setIsAdmin(true);
}
setTimeout( () => {console.log("Admin este :" + isAdmin)}, 2000);
};
getUsers();
}, []);
My problem is the following:
const [isAdmin, setIsAdmin] = useState(false);
my isAdmin
state will always be false, even if I explicitly set it inside my if
condition.
Thank you in advance!