在Cloud Functions for Firebase中从Firestore触发器获取用户ID? [英] Getting the user id from a Firestore Trigger in Cloud Functions for Firebase?

本文介绍了在Cloud Functions for Firebase中从Firestore触发器获取用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,是否有一种方法可以获取写入"offers/{offerId}"的用户的用户ID(uid)?我尝试按照所述这里,但在Firestore中不起作用.

In the example bellow, is there a way to get the user id (uid) of the user who wrote to 'offers/{offerId}'? I tried to do as described here but it doesn't work in Firestore.

exports.onNewOffer = functions.firestore
  .document('offers/{offerId}')
  .onCreate(event => {
    ...
});

推荐答案

我为此苦苦挣扎了一段时间,最后联系了Firebase支持部门:

I was struggling on this for a while and finally contacted the firebase Support:

event.auth.uid在Firestore数据库触发器的事件对象中未定义. (它适用于实时数据库触发器)

The event.auth.uid is undefined in the event object for firestore database triggers. (It works for the realtime Database Triggers)

当我console.log(event)时,我在输出中找不到任何auth.

When I console.log(event) I can’t find any auth in the output.

官方支持答案:

抱歉,Firestore SDK中尚未添加身份验证.我们在接下来的功能中列出了它.

Sorry the auth is not yet added in the Firestore SDK. We have it listed in the next features.

请留意我们的发行说明,以获取任何进一步的更新.

Keep an eye out on our release notes for any further updates.

我希望这可以节省一些时间.

I hope this saves someone a few hours.

更新:

问题已解决,该功能将永远无法实现:

The issue has been closed and the feature will never be implemeted:

大家好,大家好-另一个更新.由于技术限制,已经决定将无法实现对Firestore触发器的context.auth的本机支持.但是,工作中存在另一种解决方案,希望可以满足您的用例,但是我无法分享细节.在这个论坛上,我们通常只公开可以在功能SDK本身内部解决的问题-我将其公开,因为它似乎很重要,并且我想提供一些跟踪此工作的内部错误的更新.现在已经决定了,我将结束这个问题.再次感谢大家的耐心配合,抱歉,我没有更好的消息.请使用 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆