Skip to content
Advertisement

Firebase Cloud Functions – Issues with Promises

When running my Firebase Cloud Function orgNew there seems to be something not working correctly with my promises and the order in which the code is executed.

Console log (shortened):

JavaScript

My Firebase Cloud Function with some extra code (shortened):

JavaScript

All the other functions are not included here because they aren’t involved in the problem.

Any help is very much appreciated. Thanks!

Advertisement

Answer

From reading the code (i.e. without testing) it seems it is because you don’t return the Promises chain in the getUserAuthObject() function. Therefore userObj is undefined.

You should adapt it as follows:

JavaScript

BTW, see how we can simplify the Promises chain in this function since you don’t need to do

JavaScript

since obj does not return a Promise. It is not wrong, since then() returns a Promise but it is superfluous.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement