首页 > 解决方案 > 运行云函数时收到 [错误: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;
});

标签: node.jsfirebasereact-nativefirebase-authenticationgoogle-cloud-functions

解决方案


正如文档中强调的那样:

注意:要调用在除 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')(/* ... */)

推荐阅读