Firebase身份验证数据库规则

问题描述 投票:0回答:1

我正在开发需要连接到开发者Firebase的应用程序。此Firebase具有如下数据库规则:

"rules": {
    // no read access at root level
    ".read": "auth.uid === 'emailaddressgmailcom'",
    ".write": false,  

我不明白的是,如何将auth.uid指定为确切的电子邮件地址?据我尝试,我只能得到Google提供的唯一uid。 (一组数字和字母)因此,除非我在数据库规则中指定Google给出的确切uid,否则我永远都不能通过auth来从数据库中读取数据,这是不可行的选择,因为将有另一个用户需要访问db,而我不会知道他的uid

firebase firebase-realtime-database firebase-authentication google-authentication
1个回答
0
投票

authauth之一。

通过执行predefined variables,您将获得用户ID(“保证在所有提供者之间都是唯一的”)。

您需要在安全规则中使用它来定义给定用户对一个或多个给定资源的访问权限,如文档中的auth.uid所述。

如果特定资源应由唯一用户读取,则可以将其与固定值进行比较:

here

但是通常您将它与要保护的节点/资源路径的某些部分进行比较,例如:

".read": "auth.uid === 'HGH656675FHGFGHF3454'"

我建议您阅读有关RTDB安全规则的整个部分,以了解更多详细信息:{ "rules": { "users": { "$user_id": { // grants write access to the owner of this user account // whose uid must exactly match the key ($user_id) ".write": "$user_id === auth.uid" } } } }

© www.soinside.com 2019 - 2024. All rights reserved.