Created
October 24, 2018 22:24
-
-
Save dacre-denny/c2a202aba7cfaf375f2c5fe82899f6c5 to your computer and use it in GitHub Desktop.
Nested async/await in Firebase snapshot iteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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