I have a firebase method that is executing inside of an Object.map:
// firebase call
const getVisitors = (uid) => {
let dbRef = ref(db, `organization/${org}/visitors/${uid}`);
return get(dbRef, (snapshot) => {
const visitor = snapshot.val();
return visitor;
})
}
// where I execute method above:
Object.keys(resultData.visitors[item]).map(async visitorEl => {
const visitorObj = {};
const individualVisitor = await getVisitors(visitorEl);
console.log(individualVisitor);
Object.keys(individualVisitor).forEach(el => {
console.log(el);
})
})
I'm improperly structuring this for an asynchronous call but i'm not sure where I'm going wrong. The first console.log logs the correct data which leads me to believe it's working properly
Object {
"address": "5722 some street st",
"bDay": "",
"city": "Bsome city",
"email": "",
"first": "Richard",
"gender": "M",
"language": "Spanish",
"last": "Gongaza",
"mStatus": false,
"phone": "323555",
"profilePic": "",
"visitDate": "2022-09-11-PM",
"visitNote": "",
"zip": "",
}
but the second console.log logs which tells me the data call hasn't resolved.
_node
ref
_index
I await getVisitors. Any idea what I'm doing incorrectly?