0
votes

I'm trying to deploy a firebase cloud function. On deployment from the CLI, there was a success message, and no errors were shown.

All the other functions in this project work fine, it's just this function that doesn't.

When I try to call this function from my app I get a CORS error:

POST https://{url}/volunteering-searchPeople net::ERR_FAILED

To debug the function, I stripped everything out and it's now just this:

const searchPeople = functions.region('europe-west1').https.onCall(async (data, context) => {
  const {
    managedBy,
    helpPage,
    contactStatus,
    needs,
    postcode,
    noVolunteers
  } = data;

  return Promise.resolve('done');
})

It's called from the app here:

const testFunction = functions.httpsCallable('volunteering-testFunction')
testFunction().then((result) => console.log({result}))

It works when it's run emulated on localhost. When you go to the URL directly there's this message (which is different to the error message returned by all the other functions in this project):

Error: Forbidden
Your client does not have permission to get URL /volunteering-searchPeople from this server.

When you go to that URL, nothing appears in the logs. If I run a test directly from the Google cloud functions console, it does show up in the cloud function logs, but that seems to be the only way to actually run this function.

Edit: This now happens for all new functions I try to deploy

Edit2: This error only appears for functions deployed in europe-west1 or europe-west2. New functions in us-central1 work fine.

1

1 Answers

1
votes

You should normally not call a Callable Cloud Function through an URL but by using the dedicated methods of the Client SDK you are using (JS, Android, iOS, etc..), as explained in the doc here.

For example you would do as follows with the JS SDK:

var functions = firebase.app().functions('europe-west1');
//...
var searchPeople = functions.httpsCallable('searchPeople');
searchPeople(...).then(function(result) {
  // ...
});

On the other hand, HTTPS Cloud Functions are to be called through an URL.