英文:
"event.auth" equivalent in 2nd gen Firebase cloud functions?
问题
我正在尝试在实时数据库执行操作时(在服务器端)检索UID。我在第一代Firebase云函数中看到,可以通过访问context.auth.uid
来实现,如文档中所示。但在第二代中,文档没有提到。我该如何做?
英文:
I am trying to retrieve the uid (on server side) whenever a realtime database action is performed. I saw in the 1st Gen Firebase cloud functions, you can do it by accessing context.auth.uid
as shown in the docs. But on the 2nd Gen, the docs didn't say. How should I do it?
答案1
得分: 2
第一代Firebase云函数确实为实时数据库触发器提供了一个context.auth
参数,该参数指定了在数据库写入时在应用程序中的当前用户。
由于底层架构的更改,第二代Firebase云函数目前没有与context.auth
等效的内容。因此,目前您将不得不以与其他触发器类型一样的方式解决这个问题:通过将UID作为上下文/路径的一部分传递,并确保用户只能通过安全规则写入自己的UID。这并不是非常困难,但确实有点繁琐,因为这曾经是内置功能。
内部有兴趣将其重新引入,因此我建议在firebase.uservoice.com上提出一个功能请求,并与Firebase支持团队联系。
英文:
firebaser here
The 1st generation of Cloud Functions for Firebase indeed had a context.auth
parameter available for Realtime Database triggers that specifies the current user in the app at the time the database write was made.
There is currently no equivalent to this context.auth
in the 2nd generation of Cloud Functions, due to the changes in the underlying architecture. So for the moment, you'll have to work around this in the same way you always had to for other trigger types: by passing the UID as part of the context/path, and ensuring that users can only write to their own UID through security rules. It's not terribly difficult, but a nuisance indeed given that this used to be built-in functionality.
There is internal interest to bring it back, so I recommend filing a feature request for it on firebase.uservoice.com and with the Firebase support team.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论