Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Boxwise import data
admin
.auth()
.listUsers()
.then(listUsersResult => {
const selectedUser = listUsersResult.users.filter(
usr => usr.email.toLocaleLowerCase() === testUserEmail
);
if (selectedUser.length > 0) {
return Promise.resolve();
}
const testOrg = {
name: testOrgName,
createdAt: Date()
};
return admin
.firestore()
.collection("organizations")
.add(testOrg);
})
.then(createdTestOrg => {
// eslint-disable-next-line no-console
console.log("Successfully created new org:", createdTestOrg.id);
return admin
.auth()
.createUser({
email: testUserEmail,
password: testUserPwd,
displayName: testUserName,
emailVerified: false
})
.then(userRecord => ({ userRecord, createdTestOrg }));
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test organization:", error);
process.exit(1);
})
.then(({userRecord,createdTestOrg}) => {
// eslint-disable-next-line no-console
console.log("Successfully created new user:", userRecord.uid);
const testUser = {
name: userRecord.displayName,
organization: admin
.firestore()
.doc(`organizations/${createdTestOrg.id}`)
};
return admin
.firestore()
.collection("profiles")
.doc(userRecord.uid)
.set(testUser);
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test user:", error);
process.exit(1);
})
.then(() => {
// eslint-disable-next-line no-console
console.log("Successfully created new user profile");
process.exit(0);
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test user profile:", error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment