firebase - 无论输入或函数名称如何,httpsCallable 在使用 expo 运行模拟器并反应原生时都会返回错误:“internal”
问题描述
我们正在开发一个带有 expo 托管工作流和 firebase 的应用程序,但似乎无法在应用程序中使用 httpsCallable 触发模拟的云功能。我们总是收到“错误:内部”。该函数似乎没有被调用。从“addMessage2”更改函数名称不会更改错误。也不会改变输入。调用 httpsCallable 时产生错误。
知道什么是错的或我们应该改变什么吗?
错误:
internal
at node_modules\@firebase\auth\dist\auth.esm.js:420:103 in <anonymous>
at node_modules\@firebase\auth\dist\auth.esm.js:422:422 in <anonymous>
at node_modules\@firebase\functions\dist\index.esm.js:119:12 in _errorForResponse
at node_modules\tslib\tslib.js:84:8 in __rest
at node_modules\tslib\tslib.js:38:4 in <global>
at http://192.168.1.85:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:162043:31 in fulfilled
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
at [native code]:null in flushedQueue
at [native code]:null in callFunctionReturnFlushedQueue
客户:
// Firebase App (the core Firebase SDK) is always required and must be listed first
import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/functions'
import 'firebase/firestore'
import React from 'react'
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: '...',
authDomain: '...',
databaseURL: '...',
projectId: '...',
storageBucket: '...',
messagingSenderId: '...',
appId: '...',
measurementId: '...',
}
const app = firebase.initializeApp(firebaseConfig)
var functions = app.functions()
if (__DEV__) {
console.log('Switching to local Firebase instance...')
const origin = 'localhost'
firebase.functions().useEmulator(origin, 5001)
}
函数调用(客户端):
const addMessage = functions.httpsCallable('addMessage2')
addMessage()
.then(data => console.log('it worked', data))
.catch(error => console.error(error))
服务器:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import 'firebase-functions'
admin.initializeApp()
export const addMessage2 = functions.https.onCall((data: { text: string }, context) => {
// Checking attribute.
if (!data || !(typeof data.text === 'string') || data.text.length === 0) {
// Throwing an HttpsError so that the client gets the error details.
throw new functions.https.HttpsError(
'invalid-argument',
'The function must be called with ' +
'one arguments "text" containing the message text to add.'
)
}
// Checking that the user is authenticated.
if (!context.auth) {
// Throwing an HttpsError so that the client gets the error details.
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called ' + 'while authenticated.'
)
}
// returning result, must be able to json encode. If async, return a promise.
return {
text: 'hello',
}
})
解决方案
推荐阅读
- sql - SQL .如何查找具有几乎相同字符串值的记录?
- python - 我正在尝试创建一个代码,该代码能够计算一个人需要获得什么成绩才能获得理想的整体成绩
- windows-subsystem-for-linux - 在 WSL2 中安装 v4l2loopback
- overriding - 覆盖 prestashop 类以公开一个受保护的方法
- python - Python 正则表达式 - 从字符串中提取数字并具有正向前瞻
- python-3.x - 根据其他列中的条件创建 BOOL 列
- python - Python - 如何过滤文件列表并仅返回包含特定扩展名的值?
- typescript - 打字稿:listServiceLevelObjectives 给出 UnhandledPromiseRejectionWarning:错误:3 INVALID_ARGUMENT
- javascript - 如何在 js 构造函数上做一个数组
- javascript - 节点列表内容