I'm trying to call a callable Cloud Function from my app, but I'm facing CORS issues.
I can't enable Cors since I don't have access to the request and response on the onCall function. This is my function:
exports.UserInvitation = functions.https.onCall((data, context) => { const email = data.email return new Promise((resolve, reject) => { admin.auth().createUser({ email: email, emailVerified: false, password: password }).then(resolve).catch((err) => { console.error(err.code) reject(new functions.https.HttpsError(err.code, err.message)) }) }) })
And this is how I call it:
functions.httpsCallable('UserInvitation')({ email: this.input.value }).then((data) => { console.log('Sent invitation:', data) })
Firebase-functions package.json:
{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase serve --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "dependencies": { "bluebird": "^3.5.1", "firebase-admin": "~5.12.0", "firebase-functions": "^1.0.1" }, "private": true }
WEB SDK Firebase version: 4.13.1
For anybody else who has arrived here searching firebase callable functions cors errors, here's my checklist:
recalculatY
when it should have been recalculateY
. Got a cors error for some reason.europe-west2
. I had to both deploy the function with that region, and call it using the region. For a while, I assumed the client would infer the correct region if the function name was correct. That was not the case.Deploying a callable function to a specific region:
// This is the file in which you define your callable function. const functions = require('firebase-functions'); ... exports.yourFunc = functions.region('europe-west2').https.onCall(async (data, context) => { ... })
Calling a function in a specific region from the client (in this case, a vuejs web app):
// In my case, this is a vuex store file, but it is safe to assume this is plain old javascript import firebase from 'firebase/app' import 'firebase/functions' ... firebase.app().functions('europe-west2').httpsCallable('yourFunc')
Note: firebase.app().function...
vs firebase.app.function...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With