In order to understand how Firebase will bill me for function invocations, I have set up a scenario with two functions: newUserFlow
and addFriend
. My intention is to test whether calling newUserFlow
from within addFriend
will register as 1 or 2 functions invoked in the Firebase Console's Cloud Functions Usage tab. However, I am encountering an error.
exports.newUserFlow = functions.https.onCall((data, context) => {
return 'finished new user flow';
});
exports.addFriend = functions.https.onCall((data, context) => {
console.log('addFriend: ');
const promise = exports.newUserFlow(null, null)
promise.then(async (outputVal: string) => {
console.log('addFriend_outputVal: ', outputVal)
const uid1 = context?.auth?.uid;
if (uid1) {
var uid2: string;
const docUID2 = await admin.firestore().collection('users').where('username', '==', data.targetUser).get();
const friendsColl = 'friends_' + uid1
if (!docUID2.empty) {
docUID2.forEach(doc => {
uid2 = doc.get('uid').toString();
if (uid2) {
const docRef = admin.firestore().collection(friendsColl).doc();
return docRef.set({
friendUID: uid2,
stat: 0,
createDate: admin.firestore.FieldValue.serverTimestamp(),
modifiedDate: admin.firestore.FieldValue.serverTimestamp(),
})
}
else {
return console.log('addFriend_Error: Target uid is empty.');
}
})
}
else {
return console.log('addFriend_Error: Target user not found.');
}
}
else {
return console.log('Error: user is not authorized');
}
})
promise.catch((outputVal: string) => {
return console.log('addFriend_promisecatch')
})
});
error Promises must be handled appropriately or explicitly marked as ignored with the
void
operator