Firebase可调用函数+ CORS

问题描述 投票:6回答:2

我试图从我的应用程序调用可调用的云函数,但我正面临CORS问题。 enter image description here

我无法启用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-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版本:4.13.1

firebase google-cloud-functions
2个回答
0
投票

传递给HttpsError的状态代码不能是test/code。它必须是此处列出的标准代码之一:https://firebase.google.com/docs/reference/functions/functions.https.HttpsError


2
投票

我的问题不在于CORS,而在于我的错误处理程序。我没有拒绝承诺,而是直接在catch处理程序中使用了throw

catch((err) => {
  throw new functions.https.HttpsError('unknown', err.message, err)
})
© www.soinside.com 2019 - 2024. All rights reserved.