【问题标题】:Callable Firebase Cloud Function with region is not working具有区域的可调用 Firebase 云功能不起作用
【发布时间】:2021-03-17 08:01:47
【问题描述】:

我正在尝试从我的 Vue.js 应用程序中调用已成功部署的 Firebase Cloud Function。该函数需要从europe-west3 区域运行。

我有一个按钮被点击然后运行call() 方法:

<script>
import { functions } from '@/firebase'
export default {
  methods: {
    call() {
      const callFunction = functions('europe-west3').httpsCallable('orgNew') // Error points to this line of code
      callFunction( { name: 'John Doe'}).then(result => {
        console.log(result.data)
      })
    }
  }
}
</script>

不幸的是,这不起作用,我在控制台中收到以下错误:

在我的firebase.js 文件中,我导入了Firebase 并创建了一些助手:

import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/firestore'
import 'firebase/functions'

let firebaseConfig = { // API KEYS AND CONFIG };
firebase.initializeApp(firebaseConfig)

var db = firebase.firestore()
const auth = firebase.auth()
const functions = firebase.functions()

export {
  db,
  auth,
  functions
}

非常感谢您的帮助!

【问题讨论】:

  • 该错误消息看起来与此处的代码无关。
  • @DougStevenson 在开发工具中打开错误消息时,它正好指向我的问题中的代码行(检查更新的代码)

标签: javascript firebase vue.js google-cloud-functions


【解决方案1】:

您的代码已从 firebase.js 导出 firebase.functions()。它不是一个函数,但您的导入代码像函数一样调用它。这就是错误消息所说的你做错了。

不要导出firebase.functions(),只需导出firebase.functions,这是一个可用于初始化区域的函数。

要么,要么导出firebase.functions("europe-west3"),在导入代码中使用functions.httpsCallable()

请注意,您当前的区域字符串中有错字。

【讨论】:

  • 修正了错字。在 firebase.js 中,我将代码更改为 'firebase.functions("europe-west3)' 并像您说的那样调用它:'const callFunctionfunctions.httpsCallable("orgNew")'。现在我收到此错误:TypeError: firebase__WEBPACK_IMPORTED_MODULE_0_.functions.httpsCallable 不是函数
  • 这听起来像是一个无关的问题。我建议查看文档,记下您与捆绑器一起使用的客户端 SDK 版本:firebase.google.com/docs/web/setup#add-sdks-initialize
  • 我使用的是最新的捆绑包版本(目前 firebase@8.1.2 于 2020 年 3 月 12 日发布)。因此,我检查了正确的导入(与 v7 不同)。所以这似乎不是我认为的问题。
  • 是的,v8 中的主要导入发生了变化。
猜你喜欢
  • 2019-06-20
  • 2018-10-16
  • 2020-10-24
  • 1970-01-01
  • 2020-11-29
  • 2021-09-15
  • 2021-08-15
  • 2020-09-08
  • 2020-09-13
相关资源
最近更新 更多