According to Firebase's documentation, the following code can be used to call a onCall function named addMessage.
var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({text: messageText}).then(function(result) {
// Read result of the Cloud Function.
var sanitizedMessage = result.data.text;
})
I have a function named test, with the following code in Javascript (just to test this functionality):
exports.test = functions.https.onCall((data, context) => {
console.log(data);
data.page++;
console.log(data);
var testing = firebase.functions().httpsCallable('test');
while(data.page < 5) {
testing({page: data.page}).then(res => {
console.log("done");
})
}
});
When running this, however, I get the following error:
Unhandled error TypeError: firebase.functions is not a function
What am I doing wrong?
firebase.functions() method comes from firebase/functions package, not from firebase or firebase-functions.
const firebase = require('firebase/app');
require('firebase/functions');
const firebaseConfig = {<YOUR_CONFIG_HERE>};
const app = firebase.initializeApp(firebaseConfig);
const functions = app.functions();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With