Skip to content

Instantly share code, notes, and snippets.

@dacre-denny
Created October 24, 2018 22:24
Show Gist options
  • Save dacre-denny/c2a202aba7cfaf375f2c5fe82899f6c5 to your computer and use it in GitHub Desktop.
Save dacre-denny/c2a202aba7cfaf375f2c5fe82899f6c5 to your computer and use it in GitHub Desktop.
Nested async/await in Firebase snapshot iteration
fbDaemon = async ({ folderNames, folderPaths }) => {
const users = [];
const snapshot = await ref.once("value");
snapshot.forEach(user => {
users.push(user);
});
const settings = [];
for(const user of users) {
try {
const userRecord = await auth.getUser(user.key);
let email = userRecord.toJSON().email;
let zips = [];
user.forEach(setting => {
let dep = setting.val().department;
if (folderNames.includes(dep)) {
zips.push(dep);
}
});
settings.push({ email, zips });
}
catch(error) {
console.log("Error fetching user data:", error);
}
}
return settings;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment