为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我不能将此代码部署到Firebase函数?我不明白这个错误

为什么我不能将此代码部署到Firebase函数?我不明白这个错误

qq_笑_17 2021-05-06 10:11:22
我是Firebase函数的新手-显然-我正在尝试测试是否在创建帐户时正在使用数据库创建时在该特定路径中的电子邮件是否被某个帐户使用,然后相应地更改该数据库值。这是代码:exports.checkEmail = functions.database.ref('/checkEmailExistance')    .onCreate((snapshot, context) => {      // Grab the current value of what was written to the Realtime Database.      const email = snapshot.val();      console.log('Email:', email, context.params.pushId);      admin.auth().getUserByEmail(email)      .then(snapshot => {          const data = snapshot.toJSON()          return admin.database().ref('checkEmailExistance').child(email).set("Nope")       })});错误是:ERROR: /Users/nathan/Documents/FirebaseFunctionsClipify/functions/src/index.ts:41:7 - Promises must be handled appropriatelyERROR: /Users/nathan/Documents/FirebaseFunctionsClipify/functions/src/index.ts:42:13 - Shadowed name: 'snapshot'npm ERR! code ELIFECYCLEnpm ERR! errno 2npm ERR! functions@ lint: `tslint --project tsconfig.json`npm ERR! Exit status 2npm ERR! npm ERR! Failed at the functions@ lint script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR!     /Users/nathan/.npm/_logs/2019-04-25T16_21_29_696Z-debug.logError: functions predeploy error: Command terminated with non-zero exit code2更新:我更改了代码,因此不应再次产生该错误,但仍然遇到相同的错误:exports.checkEmail = functions.database.ref('/checkEmailExistance')    .onCreate((snapshot, context) => {      // Grab the current value of what was written to the Realtime Database.      const email = snapshot.val();      console.log('Email:', email, context.params.pushId);      return admin.auth().getUserByEmail(email)      .then(snap => {          const data = snap.toJSON()          return admin.database().ref('checkEmailExistance').child(email).set("Nope")       })    });
查看完整描述

1 回答

?
长风秋雁

TA贡献1757条经验 获得超7个赞

第二个错误是告诉您您重新定义了一个称为快照的现有变量。请注意,快照是在函数回调的顶层定义的,然后在then回调中再次定义。第二个实例是第一个实例的“阴影”,这是代码中的潜在错误。只是将第二个变量命名为不同的名称。


第一个皮棉错误是告诉您您的代码中有未处理的承诺。您可以通过以下方式返回承诺来解决此问题admin.auth().getUserByEmail().then(...):


  return admin.auth().getUserByEmail(email)

  .then(snap => {

      const data = snap.toJSON()


      return admin.database().ref('checkEmailExistance').child(email).set("Nope") 

  })


查看完整回答
反对 回复 2021-05-13
  • 1 回答
  • 0 关注
  • 124 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信