I am straggling with chaining two promises inside a loop, so that promise number two, does not start until promise one has been resolved.
I saw an example with reduce. Could not get it to work, yet. If I just do then, as I currently have, the code executes in parallel - as in, all async requests are fired off, and of course the results are messed-up. Please take a look:
for ( var i = 0; i < dummyData.accounts.length; i++) {
var cursorUser = dummyData.accounts[i];
var auth0User = {
email: cursorUser.email,
password: 'abc123',
connection: 'Username-Password-Authentication'
};
createUser(api, auth0User)
.then(function (auth0Info) {
return auth0Info;
})
.then(function(auth0Info) {
cursorUser.authProfile = auth0Info;
console.log("account: ", cursorUser);
return create(accountsAPIService, cursorUser);
})
}