1

Thank you for any help you could provide. I will be brief to save your time!

I have a cloud function (done following the official youtube tutorial):

exports.makeAdminUser = functions.region('europe-central2').https.onCall( (data, context) => {
   grantAdminRole( data.email )
})

I have an invocation (done following the official documentation, from a vuejs app):

const addAdmin = functions.httpsCallable('makeAdminUser')
addAdmin({ email: 'x@x.com'}).then( res => { console.log( res ) })

I have the permissions set for the deployed function (allUsers as the invoker, the function is public, doesn't require authentication): enter image description here

I get a CORS error, like so (trying to invoke from firebase hosting): enter image description here

What am I doing wrong?

1 Answers1

1

onCall functions behaviour differently than onRequest functions with regards to the cors, for example you need to ensure you're calling it from the same region. See this post

Example:

const addAdmin = functions('europe-west2').httpsCallable('makeAdminUser')
addAdmin({ email: 'x@x.com'}).then( res => { console.log( res ) })

The cors issue can also occur if your function is erroring, worth checking in your local emmulator.

Cleanbeans
  • 655
  • 4
  • 12
  • Thank you, the issue was the calling of the function. It automatically called from us-central1, although the functions was declared in europe-central2. The cors library was not needed. – Edgars Vilums Jun 25 '21 at 08:18