I am trying to get a response from a Firebase cloud function, but the only thing I get back is null. The console output shows that the fetch command works and outputs the correct data.
exports.create = functions.https.onCall((data, context) => {
fetch("https://mywebsite.com/x", {
method: "POST",
headers: {
"Authorization": "Bearer MyKey",
},
body: JSON.stringify({"myData":data.myData})
}).then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
return data.json();
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
});
I tried using Promise
, I tried returning is as json and just as return data
nothing seems to work. The result is always null
The code I use to call it in my flutter app:
HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('create');
final response = await callable.call(<String, dynamic>{
'myData': 'data',
}).then((value) => print(value.data));