Skip to content

Instantly share code, notes, and snippets.

@birchb
Last active April 5, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save birchb/c6b36848c4dfdf25ba348d4d16b43023 to your computer and use it in GitHub Desktop.
Save birchb/c6b36848c4dfdf25ba348d4d16b43023 to your computer and use it in GitHub Desktop.
// I use this js function inside ManageUsers.vue. It maps through an array of user data (jsonData) to call the createUser httpsCallable function.
async createNewUsers () {
this.loadingNewUsers = true
var createUser = this.$fb.functions().httpsCallable('createUser')
let promises = this.jsonData.map(person => {
// I use quasar uid to create an initial password: https://quasar.dev/quasar-utils/other-utils#Generate-UID
person.password = uid()
let jsonDatum = []
jsonDatum.push(person)
return createUser({ user: jsonDatum }) // * createUser returns a promise first
.then(result => {
console.log('returnedMessage: ', result.data.text)
let local = result.data.text + ` ${person.email}`
// If the returned response (local) starts with error, it is added to an array of error responses.
if (_.startsWith(local, 'Error')) {
this.errorMessages.push(local)
} else {
console.log('returned message: ', local)
// successMessages is a local array containing all of the positive responses from firebase.
// I display errorMessages and successMessages in the UI so that I know if it worked.
this.successMessages.push(local)
}
this.loading = false
})
})
await Promise.all(promises)
this.loadingNewUsers = false
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment