簡體   English   中英

運行雲時收到 [Error: NOT_FOUND] Function

[英]Receiving [Error: NOT_FOUND] when running a Cloud Function

當我從我的 React-Native 應用程序調用 function 時,它會拋出此錯誤: [Error: NOT_FOUND]

我研究了它,根據 Firebase 文檔,這意味着:“找不到指定的資源,或者請求被未公開的原因拒絕,例如白名單。

這是整個控制台日志消息:

[05:51:32] 我 | ReactNativeJS ▶︎ '錯誤處理',{ [錯誤:NOT_FOUND] │ 行:26115,│ 列:28,└ sourceURL:' http://localhost:8081/index.bundle?platform=android&dev=true&minify=false ' }

React-Native代碼:

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

雲 function:

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以外的任何位置運行的 function ,您必須在初始化時設置適當的值。 例如,在 Android 上,您將使用getInstance(FirebaseApp app, String region)進行初始化。

對於Firebase Javascript SDK,這個方法是firebase.app.App#functions(String region) .

所以要在上面的區域europe-west3中使用 Cloud Function,您需要更改

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM