运行云函数时收到 [Error: NOT_FOUND]

1 node.js firebase react-native firebase-authentication google-cloud-functions

当我从 React-Native 应用程序调用该函数时,它会抛出以下错误:[Error: NOT_FOUND]

\n\n

我研究了它,根据 Firebase 文档,这意味着:“找不到指定的资源,或者请求因未公开的原因(例如白名单)被拒绝。

\n\n

这是完整的控制台日志消息:

\n\n
\n

[05:51:32] 我| ReactNativeJS \xe2\x96\xb6\xef\xb8\x8e \'错误已处理\', { [错误: NOT_FOUND]\n \xe2\x94\x82 行: 26115,\n \xe2\x94\x82 列: 28, \n \xe2\x94\x94 sourceURL: \' http://localhost:8081/index.bundle?platform=android&dev=true&minify=false \' }

\n
\n\n

React-Native 代码:

\n\n
firebase.functions().httpsCallable(\'registerNewPatient\')({\n  email: \'bimiiix@hotmail.com\',\n  password: \'bbbbbb1\'\n}).then((onfulfilled, onrejected) => {\n  if (onfulfilled) {\n    console.log("OK callback function:", onfulfilled);\n  } else {\n    console.log("Error callback function:", onrejected)\n  }\n}).catch(error => { console.log("ERror handled", error) })\n
Run Code Online (Sandbox Code Playgroud)\n\n

云功能:

\n\n
exports.registerNewPatient = functions.region(\'europe-west3\').https.onCall((data, context) => {\n    if (!data.email) throw "Missing email parameter";\n    if (!data.password) throw "Missing password parameter";\n    const email = data.email;\n    const password = data.password;\n\n    admin.auth().createUser({\n        email: email,\n        emailVerified: false,\n        password: password,\n        disabled: false\n    })\n        .then(function (userRecord) {\n            registeredUser = userRecord.uid;\n            console.log(\'Successfully created new user:\', userRecord.uid);\n        })\n        .catch(function (error) {\n            console.log(\'Error creating new user:\', error);\n        });\n    return registeredUser;\n});\n
Run Code Online (Sandbox Code Playgroud)\n

sam*_*man 5

正如文档中强调的那样:

注意:要调用在默认位置以外的任何位置运行的函数us-central1,必须在初始化时设置适当的值。例如,在 Android 上,您可以使用 进行初始化getInstance(FirebaseApp app, String region)

对于 Firebase Javascript SDK,此方法是firebase.app.App#functions(String region).

europe-west3因此,要使用上述区域中的云功能,您需要更改

firebase.functions().httpsCallable('registerNewPatient')(/* ... */)
Run Code Online (Sandbox Code Playgroud)

firebase.app().functions('europe-west3').httpsCallable('registerNewPatient')(/* ... */)
Run Code Online (Sandbox Code Playgroud)

或者

const functionsEUWest3 = firebase.app().functions('europe-west3');
functionsEUWest3.httpsCallable('registerNewPatient')(/* ... */)
Run Code Online (Sandbox Code Playgroud)