![](/img/trans.png)
[英]httpsCallable is not defined when using Firebase Cloud Functions
[英]Firebase functions.httpsCallable(...).then is not a function
我正在嘗試使用我制作的功能。 所以在我的客戶中,我這樣做:
const functions = firebase.app().functions("europe-west1");
functions.httpsCallable('getSelf').then(res => {
console.log(res);
//stuff
}).catch(e => {
console.log(e);
switch (e.code) {
//stuff
}
})
基本上我得到的錯誤是functions.httpsCallable(...).then is not a function
。 我真的不明白,我沒有找到任何文檔如何在不同版本的客戶端上進行函數調用。
這是我的服務器端
// Gets things like adminlevel, profilepic etc
exports.getSelf = functions.region("europe-west1").https.onCall((data, context) => {
// Checking that the user is authenticated.
if (!context.auth)
// Throwing an HttpsError so that the client gets the error details.
throw new functions.https.HttpsError('unauthorized', 'The function must be called ' +
'while authenticated.');
return db.collection("userInformation").doc(context.auth.uid).then(user => {
if(!user)
new functions.https.HttpsError('not-found', 'The user was not found');
//returns needing values
return {
profilePicture: user.profilePicture,
adminLevel: user.adminLevel,
stripeAccountId: user.stripeAccountId,
stripeCustomerId: user.stripeCustomerId,
type: user.type
}
})
});
HttpsCallable 本身就是一個可以帶參數調用的函數,需要在里面添加另一個()
:
const getSelf = functions.httpsCallable('getSelf');
getSelf({}).then(...);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.