Gug*_*lie 2 javascript firebase google-cloud-functions react-native-firebase
我有一个带有 react-native-firebase 的 react native 应用程序,我正在尝试运行一个可调用的 https firebase 函数,该函数部署到自定义区域。
我已经读过,firebase.app().functions("MY-REGION")所以我尝试了以下操作:
import { firebase } from "@react-native-firebase/database"
import functions from "@react-native-firebase/functions"
firebase.app().functions("MY-REGION")
Run Code Online (Sandbox Code Playgroud)
但是如果我运行它,我会收到这个错误:
Error: You attempted to use
"firebase.app('[DEFAULT]').functions" but this
module could not be found.
Ensure you have installed and imported the
'@react-native-firebase/functions' package
Run Code Online (Sandbox Code Playgroud)
功能包已安装。
如果我删除@react-native-firebase/functions导入,错误保持不变。
如何在 中指定 firebase https 函数的区域react-native-firebase?
firebase.initializeApp({
...options
})
firebase.app().functions("MY-REGION")
Run Code Online (Sandbox Code Playgroud)
那说 Error: Firebase App named '[DEFAULT]' already exists
firebase.initializeApp({
...options
}, "APP_NAME")
firebase.app("APP_NAME").functions("MY-REGION")
Run Code Online (Sandbox Code Playgroud)
给 Error: No firebase App 'APP_NAME' has been created - call firebase.initializeApp()
我希望我错过了一些微不足道的东西。
一个解决方案是将函数导入从 更改import functions from "..."为import "...":
import { firebase } from "@react-native-firebase/database"
import "@react-native-firebase/functions" // <--
// call a https firebase function
firebase.app().functions("MY-REGION").httpsCallable('MyFunction')()
Run Code Online (Sandbox Code Playgroud)
请注意,MY-REGION应设置为所选 httpsCallable 函数的 firebase 函数仪表板中显示的区域。
我发现的修复确实非常简单......
我已经在这里分享了它,所以它可以对其他人有用,但欢迎更好的解决方案!