node.js - 运行云函数时收到 [错误:NOT_FOUND]
问题描述
当我从我的 React-Native 应用程序调用该函数时,它会抛出此错误:[Error: NOT_FOUND]
.
我对其进行了研究,根据 Firebase 文档,这意味着:“找不到指定的资源,或者请求因未公开的原因被拒绝,例如白名单。 ”
这是整个控制台日志消息:
[05:51:32] 我 | ReactNativeJS ▶︎'错误处理',{ [错误:NOT_FOUND]│行:26115,│列:28,└ sourceURL:' http://localhost:8081/index.bundle?platform=android&dev=true&minify=false '}
反应原生代码:
firebase.functions().httpsCallable('registerNewPatient')({
email: 'bimiiix@hotmail.com',
password: 'bbbbbb1'
}).then((onfulfilled, onrejected) => {
if (onfulfilled) {
console.log("OK callback function:", onfulfilled);
} else {
console.log("Error callback function:", onrejected)
}
}).catch(error => { console.log("ERror handled", error) })
云功能:
exports.registerNewPatient = functions.region('europe-west3').https.onCall((data, context) => {
if (!data.email) throw "Missing email parameter";
if (!data.password) throw "Missing password parameter";
const email = data.email;
const password = data.password;
admin.auth().createUser({
email: email,
emailVerified: false,
password: password,
disabled: false
})
.then(function (userRecord) {
registeredUser = userRecord.uid;
console.log('Successfully created new user:', userRecord.uid);
})
.catch(function (error) {
console.log('Error creating new user:', error);
});
return registeredUser;
});
解决方案
正如文档中强调的那样:
注意:要调用在除 default 以外的任何位置运行的函数
us-central1
,您必须在初始化时设置适当的值。例如,在 Android 上,您将使用getInstance(FirebaseApp app, String region)
.
对于 Firebase Javascript SDK,此方法是firebase.app.App#functions(String region)
.
因此,要在上述区域中使用云功能europe-west3
,您需要更改
firebase.functions().httpsCallable('registerNewPatient')(/* ... */)
至
firebase.app().functions('europe-west3').httpsCallable('registerNewPatient')(/* ... */)
或者
const functionsEUWest3 = firebase.app().functions('europe-west3');
functionsEUWest3.httpsCallable('registerNewPatient')(/* ... */)
推荐阅读
- python - 在 Keras 模型 weighta 上执行 np.isnan 失败并出现 TypeError:输入类型不支持 ufunc 'isnan'
- python - 如何创建多维索引数组?
- php - 检查一个日期是否在另一个日期?
- ajax - 关于 drupal 7 中的问题 500 服务不可用
- batch-file - 循环通过批处理文件中的逗号分隔字符串
- apache-flink - 如何通过 flink 中同一插槽上的某个键聚合日期,以便我可以节省网络调用
- java - 将数组的所有索引添加到一个数组
- reactjs - 带有 React 和 Firebase 登录弹出问题的 Electron
- python - 张量流中的 4X + 2 = 0
- microsoft-graph-api - 如何验证域以便可以将架构扩展添加到 ms 图中?