1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Yeah I know that. The CORS error was what I got when I used it properly in the app. I tried calling it through a URL because it kept returning strange errors. Even if you do call a function from a URL though, an error appears in the logs, but not for this one.
Can you share the entire code used when you call it the standard way. (Cloud Function + Client code)
Sure, I have done. I really don't think it's an issue in the code on the app though. We have ~80 httpsCallable functions that work fine. It's just any new ones we create that seem to have this issue.
Are all the ones working fine declared with region('europe-west1') as well? It seems you don't declare the region in your client.
Yeah we've declared the region when we initialise firebase because all the functions are in europe-west1. This is the relevant code: const REGION = 'europe-west1' const fireFunctions = fire.functions(REGION) fire.functions = () => fireFunctions export default fire` and then: const functions = fire().functions
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.