Reputation: 798
Client Callable Firebase Function fails with "Error: The data couldn’t be read because it isn’t in the correct format." when deployed to regions other than us-central1 (tried Europe West and Asia).
Server Code
exports.getName = functions.region('europe-west1').https.onCall((data, context) => {
return { name: "Testopoulos" };
});
Client Code (React Native Firebase)
const httpsCallableUserName = firebase.functions().httpsCallable('getName');
getUserName = () => {
httpsCallableUserName()
.then(({ data }) => {
console.log(data.name);
})
.catch(httpsError => {
console.log(httpsError);
})
}
There is a note in the docs saying that "[when] using HTTP functions to serve dynamic content for hosting, you must use us-central1" but I am just returning an object to our frontend React Native client and not using Firebase Hosting. I read other posts about the regions but I don't think it is the same case. Any ideas?
Upvotes: 6
Views: 1758
Reputation: 1389
IN 2023 Firebase 10 it's slightly different
initializeApp(firebaseConfig)
const functions = getFunctions();
functions.region = 'europe-west3';
works for me :-)
Upvotes: 0
Reputation: 83068
According to the documentation "the client can also specify a region, and must do so if the function runs in any region other than us-central1
.".
As you have found (see comments above), it has to be done with:
var functions = firebase.initializeApp(config).functions('europe-west1');
Upvotes: 14