发送回客户端的数据返回“未定义”

时间:2019-10-21 16:58:05

标签: javascript

我有一个可调用的云功能,除了我发送给客户端的消息以undefined的形式返回外,它似乎完全正常运行。

我当前的设置如下:

来自客户端的函数调用:

 const myFunction = async => {
    let fn = firebase.functions().httpsCallable("testFunction");
    try {
      const response = await fn({ sentData: some_data});
      console.log(response.data.backendResult);
    } catch (err) {
      alert(err);
    }
  };

云函数调用:

// functions/index.js

exports.testFunction = functions.https.onCall((data, context) => {

 const { otherFunc } = require("./otherFunc");
 ...
 return otherFunc(arg, { backendResult: "success" });
}

// functions/otherFunc.js

const otherFunc = async (
  someDoc,
  obj
) => {
  try {
    await someDoc.set(
      {
        content: "test"
      }
    );
    console.log(obj.backendResult);
    return obj.backendResult;
  } catch (err) {
    console.log(err);
  }
};

module.exports = { otherFunc};

数据正在正确写入Firestore,并且obj.backendResult在我的日志中正确记录,但是数据在客户端返回undefined

1 个答案:

答案 0 :(得分:2)

不是Google云专家,而是在您的otherFunc函数中,您不应该返回obj而不是obj.backendResult吗?

相关问题