node.js - 为什么我仍然有警告:即使我已经返回了一个承诺,也应该在云函数中的异步箭头函数的末尾返回一个值?
问题描述
我是 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
已经firebase deploy
在
警告:预期在异步箭头函数一致返回的末尾返回一个值
解决方案
你在try catch块之外缺少返回值,如果出现异常,函数没有返回,修改函数如下
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
})
推荐阅读
- asp.net - 使用 .Net Core 的 SSRS 报告
- android-studio - Android Studio Flutter 热重载和热重启按钮被禁用并停留在真实 iOS 设备上的“安装和启动”
- .htaccess - 我的 .htaccess 文件无法删除 .html 扩展名
- ubuntu - 在 Yocto 上安装 Mosquitto
- javascript - 如何动态多次渲染组件
- java - 如何在客户端安全地保护服务器身份验证密码?
- json - 如何在 mule 4 中将 ManagedCursorStreamProvider 转换为 JSOn 对象
- python - pyscreenshot 无需登录即可获取远程 Windows 服务器的屏幕截图
- postgresql - 即使将语言更改为英语,Pgadmin 仍以瑞典语显示错误
- npm - 我收到错误消息“未完成加载插件”