知道Firebase Cloud Function的用户标识,只允许该功能在Firebase规则中写入 [英] Know the user id for a Cloud Function for Firebase to allow only to the function to write inside Firebase Rules

查看:148
本文介绍了知道Firebase Cloud Function的用户标识,只允许该功能在Firebase规则中写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能知道Firebase云端功能的ID(数据库触发器)在Firebase规则中使用该ID吗?我只需要允许这个函数写入Firebase数据库。

更新:
为了说明问题,我使用的是Firebase数据库的Firebase功能,写入数据库,只允许用户阅读,然后我发现这种方法只允许对Firebase云功能的写入权限并在此之后,aproach给我的错误默认的Firebase应用程序已经存在。,但我发现这种方法是不同的,这个链接是关于谷歌云功能,而不是关于Firebase功能功能),我没有发现其他相关的问题。我找到的答案是在下面发布的。

解决方案

似乎Firebase和Google云功能的云端函数存在误解错误消息是因为用于Firebase云端功能的Google云端函数代码),但无论如何,这个问题的答案是您可以使用 adminRef ,而不是引用将在Firebase数据库上写入数据的函数的代码:

event.data.adminRef 改为 event.data.ref



这将给你完整的读写访问权限,而不是最终用户访问权限(请注意,你也必须注意在规则中注明否认每个人)。

Is possible to know the id of a Cloud Function for Firebase (database trigger) to use that id within Firebase Rules? I need to allow only to this function to write to the Firebase database.

Update: To clarify, I am using a Trigger Database Firebase function, and I want to allow only to that function to write to the database, and allow only to users read, then I found this approach Allowing write access only to Cloud Functions for Firebase and following that aproach give me the error "The default Firebase app already exists.", but I found that this approach is different, this link is about Google Cloud function and not about a Firebase function (trigger database function), and I have no found other questions related. The answer that I found was posted below.

解决方案

Seems that there is a misunderstood about Cloud Functions for Firebase and Google Cloud Functions (the error message is because is used code for a Google Cloud Functions within a Cloud Function for Firebase), but anyway the answer of this question is that you can use adminRef instead ref in the code of the function that will write the data on Firebase database:

event.data.adminRef instead event.data.ref

this will give you full read and write access instead of end-user access (please note that also you must take care to indicate within the rules deny to everybody).

这篇关于知道Firebase Cloud Function的用户标识,只允许该功能在Firebase规则中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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