[Vuejs]-Firebase GET request not returning data to client

1👍

I haven’t tried your code but the problem is most probably due to the fact you don’t return the promise chain in your Cloud Function.

You should either do:

  return axios({  // <====== See return here
    // ...
  })
  .then(response => {
    functions.logger.log("Response", " => ", response.data);
    return response.data
  })
  .catch((error) => {
    functions.logger.log("Error", " => ", error);
  })

or, since you declared the function async, use the await keyword as follows:

exports.retrieveByExternalId = functions.https.onCall(async (data, context) => {

    try {
        const id = data.id

        const axiosResponse = await axios({
            method: "GET",
            url: `https://website/api/v2/workers/external/${id}`,
            headers: {
                accept: '*',
                'Access-Control-Allow-Origin': '*',
                Authorization: 'API KEY'
            }
        });

        functions.logger.log("Response", " => ", axiosResponse.data);
        return axiosResponse.data
    } catch (error) {
        // see https://firebase.google.com/docs/functions/callable#handle_errors
    }
    
});

Leave a comment