Last active
April 5, 2020 16:44
-
-
Save birchb/c6b36848c4dfdf25ba348d4d16b43023 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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