每当我运行"firebase deploy-only functions"时,它都会出现此错误分析函数触发器时出错。
TypeError:functions.https.onCall(…(.then不是函数在对象处。(C:\Users\Lenovo\Desktop\Firebase Revision\functions\index.js:11:4(在模块中_compile(internal/modules/cjs/loader.js:1158:30(位于Object.Module_extensions.js(internal/modules/cjs/loader.js:1178:10(在Module.load(internal/modules/cjs/loader.js:1002:32(位于Function.Module_load(internal/modules/cjs/loader.js:901:14(在Module.require(internal/modules/cjs/loader.js:1044:19(at required(internal/modules/cjs/helpers.js:77:18(位于C:\Users\Lenovo\AppData\Roaming\npm\node_modules\firebase-tools\lib\trigerParser.js:15:15在对象处。(C:\Users\Lenovo\AppData\Roaming\npm\node_modules\firebase-tools\lib\trigerParser.js:53:3(在模块中_编译(internal/modules/cjs/loader.js:1158:30(
以下是我在index.js函数中的代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.addAdminRole = functions.https.onCall((data,context) => {
return admin.auth().getUserByEmail(data.email).then(user => {
return admin.auth().setCustomUserClaims(user.uid,{
admin: true
});
})
}).then(()=>{
return {
message: `Success! ${data.email} has been made an admin`
}
}).catch(err => {
return err;
})
您没有正确地链接then()
方法。你应该做如下:
exports.addAdminRole = functions.https.onCall((data, context) => {
return admin.auth().getUserByEmail(data.email)
.then(user => {
return admin.auth().setCustomUserClaims(user.uid, {
admin: true
});
})
.then(() => {
return {
message: `Success! ${data.email} has been made an admin`
}
}).catch(err => {
return err;
})
})
请注意,与其进行
.catch(err => {
return err;
})
您应该按照文档了解如何处理可调用云函数中的错误。