Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase callable function not receiving arguments

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.

like image 417
Danilo Fuchs Avatar asked Dec 17 '25 10:12

Danilo Fuchs


2 Answers

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.

like image 111
Jen Person Avatar answered Dec 20 '25 00:12

Jen Person


//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)}`);
        });
like image 30
Genís Martínez Avatar answered Dec 19 '25 23:12

Genís Martínez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!