Home > Enterprise >  Firebase functions query parameters are null
Firebase functions query parameters are null

Time:12-08

I am having difficulty passing query parameters to my firebase (google cloud) functions, they are continuously empty, but otherwise the function completes as normal. Can anyone identify whats going wrong?

Cloud Function Code

exports.message = functions.https.onRequest((request, response) => {
   functions.logger.log("log query");
   functions.logger.log(request.query);
  response.json({result: `done`});
});

Local application code:

export const sendPushNotification = async (options) => {
  try {
    const db = firebase.firestore();
    const fbFunctions = firebase.functions();

    const message = fbFunctions.httpsCallable("message");
   message({text:"asdfasdf"})
  
  } catch (error) {
    console.log({ error });
    switch (error.code) {
      default:
        return {
          error: "Error.",
        };
    }
  }
};

CodePudding user response:

It's not possible to use the Firebase Functions SDK to invoke onRequest type functions. The Firebase SDK implements the client side of a enter image description here 3. Run npm install [email protected] --save
4. Manually require both Firebase core and Cloud Functions:

const firebase = require("firebase");
// Required for side-effects
require("firebase/functions");
  1. Initialise the Client SDK using :

enter image description here

  1. Call the function using: enter image description here
  • Related