Implementing a simple function on typescript to call a Firebase callable function is not working. Using [email protected] -g, [email protected], [email protected]
Firebase callable function:
import * as functions from "firebase-functions";
exports.httpsOnCall = functions.https.onCall((data, context) => {
console.log(data);
return data;
});
It is deployed correctly
Calling the function in webapp:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a.call({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
Firebase object initialization:
import * as firebase from "firebase";
const config = {
apiKey: "asdasdasd",
authDomain: "APPNAME.firebaseapp.com",
databaseURL: "https://APPNAME.firebaseio.com",
projectId: "APPNAME",
storageBucket: "APPNAME.appspot.com",
messagingSenderId: "123456"
};
firebase.initializeApp(config);
const Firebase = {
functions: firebase.functions()
}
Log from firebase:
null
Log from webapp:
{data: null}
It seems like data is not reaching the httpsOnCall function, even though the context variable is populated.
Instead of doing a.call, just call the function a with the parameters, like this:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
See the guide for an example.
//imports
const firebase = require("firebase");
require("firebase/functions");
//call steatment
const a = firebase.functions().httpsCallable('httpsOnCall');
a({ a: 1, b: "testing", c: true })
.then((result) => {
console.log(result);
})
.catch((error) => {
console.log(`error: ${JSON.stringify(error)}`);
});
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