【问题标题】:Firestore onWrite trigger doesn't have auth informationFirestore onWrite 触发器没有身份验证信息
【发布时间】:2018-05-06 17:23:44
【问题描述】:

当我从登录的 Android 客户端向 Firestore 写入数据时, 我无法获取 onWrite 触发器的身份验证信息。

当我打印应该使用 UID 存储身份验证对象的上下文对象时,我看到身份验证对象不存在。

根据这个链接,https://firebase.google.com/docs/functions/beta-v1-diff?authuser=0#new_properties_for_user_auth_information

我应该获得有关 Firestore 上任何写入的信息。

这是我使用的示例代码。

exports.testTrigger = functions.firestore
    .document('col1/doc1/col2/{doc2}')
    .onWrite((change, context) => {

        console.log('context = ', context);
        const auth = context.auth;
        console.log('auth = ', auth);

});

云函数日志中的输出:

context =  { eventId: '3c2295a4-2823-4fba-b406-728d7d77f6de-0',
  timestamp: '2018-05-06T17:11:12.771855Z',
  eventType: 'google.firestore.document.write',
  resource: 
   { service: 'firestore.googleapis.com',
     name: 'projects/xyz/databases/(default)/documents/col1/doc1/col2/gFRWgJg37DmB5wchWLBV' },
  params: { request_id: 'gFRWgJg37DmB5wchWLBV' } }

auth = undefined

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    您链接到的文档是关于实时数据库触发器,而不是 Firestore。仔细查看章节标题。

    目前,Firestore 触发器中未提供身份验证信息。将来可能会提供。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2012-12-30
      • 2015-03-25
      • 2021-07-23
      • 2019-11-22
      • 2015-03-17
      相关资源
      最近更新 更多