Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client Callable Firebase Function fails when deployed to regions other than us-central1

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?

like image 261
Va5ili5 Avatar asked Aug 09 '18 16:08

Va5ili5


People also ask

What is the difference between onCall http callable and onRequest HTTP request functions?

onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.

What is HttpsCallable?

An HttpsCallable is a reference to a "callable" http trigger in Google Cloud Functions.


1 Answers

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');
like image 73
Renaud Tarnec Avatar answered Oct 18 '22 20:10

Renaud Tarnec