The callback of the first rule
callback(null, user, context);
is outside of the request {...}
, so that calling is executed without waiting for the request() to finish, as the request runs async.
It should be inside that request, like this:
request(opt, function (er, response, body2) {
console.log("This should come 1st");
if (er) {
throw new Error(er)
} else {
callback(null, user, context);
}
});
But also note, since you actually have 2 request in your first rule: these requests also don’t wait for each other, so you never know which of the two requests will finish first. Might make sense to call this in a nested as well.