Thanks @alex-egli this was very helpful
Here's my version which is based on yours with 3 small changes
avoid an eslint warning https://eslint.org/docs/rules/no-await-in-loop
(I don't think your code is bad here and the warning could be muted)
add in a check that this is being run on the emulator
added user display name
exports.populateAuthUsers = functions.https.onRequest(async (req, res) => {
if (!process.env["FUNCTIONS_EMULATOR"]) {
return res
.status(403)
.send("ACCESS DENIED. This function is ONLY available via an emulator");
}
const users = [
{
uid: "user1",
displayName: "one Local Admin",
email: "[email protected]",
password: "password",
},
{
uid: "user2",
displayName: "two Local Admin",
email: "[email protected]",
password: "password",
},
// put all test users you want populated here
];
const results = [];
const promises = [];
for (let user of users) {
let promise = admin
.auth()
.createUser(user)
.then((result) => {
return result;
})
.catch((error) => {
return error.message; // continue on errors (eg duplicate users)
});
promises.push(promise);
}
await Promise.all(promises).then((result) => {
results.push(result);
return;
});
res.header("Content-type", "application/json");
return res.status(200).send(JSON.stringify(results));
});