我正在尝试从我的应用程序调用可调用的云函数,但我面临 CORS 问题。
我无法启用 Cors,因为我无权访问 onCall 函数上的请求和响应。这是我的功能:
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))
})
})
})
这就是我所说的:
functions.httpsCallable('UserInvitation')({ email: this.input.value }).then((data) => {
console.log('Sent invitation:', data)
})
Firebase 函数 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 版本:4.13.1