javascript - Firebase 可呼叫函數未接收到參數
在 TypeScript 上實現一個簡單的函數以調用 Firebase 可調用函數不起作用。使用 [email -g、[email 、[email
Firebase 可調用函數:
import * as functions from "firebase-functions";
exports.httpsOnCall = functions.https.onCall((data, context) => {
console.log(data);
return data;
});
它已正確部署
在網頁應用程式中呼叫函數:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a.call({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
Firebase 物件初始化:
import * as firebase from "firebase";
const config = {
apiKey: "asdasdasd",
authDomain: "APPNAME.firebaseapp.com",
databaseURL: "https://APPNAME.firebaseio.com",
projectId: "APPNAME",
storageBucket: "APPNAME.appspot.com",
messagingSenderId: "123456"
};
firebase.initializeApp(config);
const Firebase = {
functions: firebase.functions()
}
來自 Firebase 的日誌:
null
來自網頁應用的日誌:
{data: null}
看起來數據沒有到達 httpsOnCall 函數,即使 context 變數已經有值。
答案#1
與其使用 a.call,不如直接用參數呼叫函數 a,像這樣:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
請參閱指南以獲取示例。
