簡體   English   中英

使用 Functions 和 Admin 時出現 Firebase“內部”錯誤

[英]Firebase 'internal' error when using Functions and Admin

我遇到了一些以前一直在工作的功能。 我創建了一個函數讓用戶創建另一個用戶,它工作正常。 不使用 Admin 的功能和以前一樣工作正常。

但是,由於某些 Firebase 更新,該功能中斷,我收到“內部”錯誤。 我不得不import firebase from "firebase/app"; import firebase from "firebase/compat/app"; 以及import "firebase/compat/functions"; 但這不起作用,以及將firebase更新為"^9.8.1" ,但這也不起作用。

這是我的網絡功能:

async registerUser(userInfo) {
    const functions = getFunctions();
    const createUser = httpsCallable(functions, "createUser");
      // Used to have this: 
      // let createUser = firebase.functions().httpsCallable("createUser");

    //Call to function where it breaks.
    return await createUser({
       //User data here
    })
      .then( 
    //stuff happens here
    ).catch((error) => {
      //Error happens here
})
}

這是已經部署在 Firebase 中的函數:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

  exports.createUser = functions.https.onCall(async (userData) => {
    return await admin
    .auth()
    .createUser(userData)
    .then(() => {
      return { isError: false };
    })
    .catch((error) => {
      return { isError: true, errorMessage: error };
    });
});

這是響應日志:

Request Method: OPTIONS
Status Code: 403 
Referrer Policy: strict-origin-when-cross-origin
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
content-length: 305
content-type: text/html; charset=UTF-8
date: Tue, 24 May 2022 16:04:14 GMT
server: Google Frontend

您可以參考Admin SDK 錯誤處理頁面並檢查錯誤的結構refer to policy: strict-origin-when-cross-origin部分為我們提供了一個很好的起點。

但首先,我們可以看到此問題的根本原因,因為在同一頁面中,我們有一個平台錯誤代碼表,其中:

內部 | 內部服務器錯誤。 通常是服務器錯誤。

在 Firebase Admin Authentication API Errors我們有一個類似的表,其中:

身份驗證/內部錯誤 | 身份驗證服務器在嘗試處理請求時遇到意外錯誤。 錯誤消息應包含來自身份驗證服務器的響應,其中包含附加信息。 如果錯誤仍然存​​在,請將問題報告給我們的錯誤報告支持渠道。

現在談論 cors 消息,這個問題表明:

考慮像這樣導入,如示例所示:

 const cors = require('cors')({origin: true});

你的函數的一般形式是這樣的:

 exports.fn = functions.https.onRequest((req, res) => { cors(req, res, () => { // your function body here - use the provided req and res from cors }) });

由於問題有一段時間,您可能需要對結構進行一些更改,因此我還將通過 HTTP 請求保留對 Call 函數的引用,並檢查它是否適合您。

如果您提供更新,我會跟進,如果有必要,請考慮提交文檔前面提到的 錯誤報告

暫無
暫無

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

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