我正在尝试使用我制作的函数。所以在我的客户端中我这样做:
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不是一个函数
。我不太明白,也没有找到任何文档如何在不同版本的客户端上进行函数调用。
这是我的服务器端
// 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(...);
关于javascript - Firebase 函数。httpsCallable(...).then 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59650644/