我是 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/