I have a React Native - Expo application, and I recently implemented a basic cloud function using the firebase-functions/v2/https onCall() like so:
exports.addmessage = onCall((request) => {
logger.info("Request: " + request.data.text);
return {text: request.data.text}
});
I deploy this function, and it gets deployed seemingly correct. Then I try to call this function from my client code in the App - component like so:
export default function App() {
const addmessage = httpsCallable(functions, 'addmessage');
function callFunction() {
addmessage({ text: "Hello world!" })
.then((result) => {
console.log("Function called");
console.log(result);
}).catch((error) => {
console.log("Function call failed");
console.log(error)
});
}
return (
<SafeAreaProvider>
<SafeAreaView style={styles.container}>
<Button title="Call cloud function" onPress={() => callFunction()}></Button>
<StatusBar style="auto" />
</SafeAreaView>
</SafeAreaProvider>
);
}
When I click the button to call the cloud function, I get "Function call failed" and "[FirebaseError: internal]". Is this the correct way to call the callable function? I have checked the logger for the function inside the firebase portal, but no errors are logged there. What can I do to find/fix this issue? I have tested with an onRequest-function, and this works as expected.
I use "firebase": "9.22.1" as dependency in project-package.json (though I have also tested with "firebase": "9.20.0") In my functions package.json, I have these dependencies: "firebase-admin": "^11.8.0", "firebase-functions": "^4.3.1".