firebasefunctioncloudhostingvuejs3

Firebase callable cloud function CORS error, but allUsers is already set as invoker


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?


Solution

  • 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 emulator.