javascript - Firebase 函数。httpsCallable(...).then 不是函数

标签 javascript firebase

我正在尝试使用我制作的函数。所以在我的客户端中我这样做:

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/

相关文章:

javascript - nodejs回调不明白回调结果是如何通过参数来的

firebase - 用于在用户之间共享文档的 Firestore 数据库规则和结构

javascript - 如何在ReactJS中将应用程序状态传递给后端?

javascript - 有什么方法可以使用 javascript 来检测 javascript 事件处理程序触发吗?

javascript - 仅将根 URL 重定向到 Firebase 中的某个其他文件

firebase - 无法使 Firestore 规则中包含 'get' 部分的函数正常工作

android - 从后台服务从 Firebase 存储下载文件

sorting - Firestore 分页 - 是否有与 firebase 的 limitToLast 兼容的查询?

javascript - Canvas 跟随鼠标光标画线

javascript - 按钮点击在移动设备上不起作用