gpt4 book ai didi

firebase - 如何为使用 Cloud Firestore 的 Flutter 应用设置安全规则?

转载 作者:IT王子 更新时间:2023-10-29 07:12:50 26 4
gpt4 key购买 nike

我正在创建一个 Flutter 移动应用程序,并希望使用 Cloud Firestore 来存储客户端应该访问的一些数据。到目前为止,没有特定于用户的数据,所以我不希望我的用户必须在应用程序中登录。我需要指定哪些安全规则以允许客户端读取数据,但拒绝公共(public)访问(从应用“外部”)?

这些是我到目前为止设置的安全规则。

service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow write: if false;
allow read: if request.auth.uid != null;
}
}
}

在身份验证 --> 登录方法下,我启用了匿名身份验证。但是我不确定安全规则是否正确以及我需要在客户端中使用哪些 Dart 代码来获得所需的行为(不需要客户端指定凭据,但可以保护我的数据不被应用程序外部访问)。

最佳答案

so I don't want my users to have to login in the app.

但是你验证了它们。即使是匿名认证,也是认证。

What security rules do I need to specify to allow clients to read data, but deny public access (from "outside" of the app)?

您已经拥有的确切规则。

But I'm not sure if the security rules are correct.

规则是正确的。

what Dart code I need in the client to get the desired behavior (no need for client to specify credentials, but protection of my data from access outside of the app).

您的代码应类似于 this .

关于firebase - 如何为使用 Cloud Firestore 的 Flutter 应用设置安全规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53957711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com