node.js - 为什么即使我已经返回了一个 promise ,我仍然有警告 : Expected to return a value at the end of async arrow function in cloud function,?

标签 node.js firebase google-cloud-functions

我是 NodeJS 和 Firebase 云函数的新手,这是我在 Firebase 云函数中的代码:

exports.dbModeratorsOnCreate = functions.firestore.document('moderators/{moderatorID}').onUpdate(async (change,context) => {

    // grant custom claim to the newly created moderator

    try {

        const moderatorID = context.params.moderatorID

        return admin.auth().setCustomUserClaims(moderatorID, {
            moderator: true
        })

    } catch(error) {
        console.log(error)
    }

})

如您所见,我在 return admin.auth().setCustomUserClaims(moderatorID 中返回了一个 promise ,但是为什么当我使用 firebase deploy 部署时我仍然有终端中的警告说

warning : Expected to return a value at the end of async arrow function consistent-return

最佳答案

你在 try catch block 之外缺少返回值,以防出现异常,函数没有返回,按如下方式修改函数

exports.dbModeratorsOnCreate = functions.firestore.document('moderators/{moderatorID}').onUpdate(async (change,context) => {

    // grant custom claim to the newly created moderator

    try {

        const moderatorID = context.params.moderatorID

        return admin.auth().setCustomUserClaims(moderatorID, {
            moderator: true
        })

    } catch(error) {
        console.log(error)
    }
    return null
})

关于node.js - 为什么即使我已经返回了一个 promise ,我仍然有警告 : Expected to return a value at the end of async arrow function in cloud function,?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59487046/

相关文章:

javascript - 获取文档的值

java - Firebase .orderByChild - 尝试对数字进行排序,但它只对第一个数字进行排序

firebase - 在firebase中存储富文本

javascript - 将 Google STT 从云功能转移到专用 GAE

javascript - 如何从 JSON 文件将日期插入 mongo

node.js - 如何为所有 Node/快速路由添加前缀

firebase - Firebase Cloud Functions 可以将 OAuth2 与 gmail 一起使用吗?

firebase - 如何使用 Firebase Auth 同步自定义声明 token

node.js - 如何部署使用 Redis 的 Meteor 应用程序?

node.js - EncloseJS 与 Nexe