从 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)?我尝试按照

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

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

官方支持答案:

<块引用>

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

请密切关注我们的发行说明以获取任何进一步更新.

我希望这可以为某人节省几个小时.

更新:

问题已被关闭,该功能将永远不会实现:

<块引用>

大家好,又是一个更新.遗憾的是,由于技术限制,将不会实现对 Firestore 触发器的 context.auth 的本机支持.但是,工作中有一个不同的解决方案,希望能满足您的用例,但我不能分享细节.在这个论坛上,我们通常只开放可以在函数 SDK 本身内部解决的问题 - 我一直保持开放,因为它看起来很重要,我想提供一些关于跟踪这项工作的内部错误的更新.既然已经做出决定,我将关闭它.再次感谢大家的耐心等待,很抱歉我没有更好的消息.请使用 此处.

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 => {
    ...
});

解决方案

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

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

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

The official support answer:

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.

UPDATE:

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

Hi there again everyone - another update. It has been decided that unfortunately native support for context.auth for Firestore triggers will not be implemented due to technical constraints. However, there is a different solution in the works that hopefully will satisfy your use case, but I cannot share details. On this forum we generally keep open only issues that can be solved inside the functions SDK itself - I've kept this one open since it seemed important and I wanted to provide some updates on the internal bugs tracking this work. Now that a decision has been reached, I'm going to close this out. Thanks again for everyone's patience and I'm sorry I don't have better news. Please use the workaround referenced in here.

这篇关于从 Cloud Functions for Firebase 中的 Firestore 触发器获取用户 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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