运行云功能时接收[错误:NOT_FOUND]



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

我对此进行了研究,根据Firebase的文档,这意味着:"没有找到指定的资源,或者由于未公开的原因(如白名单(拒绝了请求。">

以下是整个控制台日志消息:

[05:51:32]I|ReactNativeJS▶︎ 'ER已处理错误',{[错误:NOT_FOUND]│线路:26115,│列:28,└源URL:'http://localhost:8081/index.bundle?platform=android&dev=true&minify=false'}

React本机代码:

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;
});

如文档中突出显示的:

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

除了@samthecodingman对区域的出色回答外,您的代码中也没有正确处理异步API。到您的return registeredUser现在运行时,还没有调用registeredUser = userRecord.uid。我建议在将来使用一些额外的日志记录语句来解决这种类型的行为。

这应该更接近:

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;
return admin.auth().createUser({
email: email,
emailVerified: false,
password: password,
disabled: false
})
.then(function (userRecord) {
return userRecord.uid;
console.log('Successfully created new user:', userRecord.uid);
})
.catch(function (error) {
console.log('Error creating new user:', error);
throw new functions.https.HttpsError('Error creating user', error);
});
});

相关内容

  • 没有找到相关文章

最新更新