firebase - 任何人都可以帮我编辑亚马逊等电子商务应用的 Firebase 规则吗
问题描述
谁能帮我编辑电子商务应用程序的firebase规则,因为我收到来自firebase的邮件说你的firebase规则不安全。我需要它们用于firebase firestore。
解决方案
仅用于开发,您可以使用它。不用于生产
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
// EVERYUSER CAN EDIT AND DELETE YOUR DATA. NOT FOR PRODUCTION.
}
}
}
当您了解 Firestore 规则的工作原理时,这应该会为您提供指导。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isLoggedIn() {
return request.auth != null;
}
function isOwner() {
// where ownerId is the id of the owner
return isLoggedIn() && resource != null && (resource.data.ownerId == request.auth.uid);
}
match /posts/{postId} {
// for an ecommerce app,
// everybody should be able to view posts
allow read: if true;
// only logged in users should be able to create posts
allow create: if isLoggedIn();
// only the owner of a post should be able to edit/delete posts
allow update, delete: if isOwner();
}
match /users/{userId} {
// You should be able to get, edit and delete only your data
allow get, write: if isOwner();
// no body should be able to get list of your users
allow list: if false;
}
}
}
推荐阅读
- javafx - 使用 Slider 更新 SwingNode 中的 Jfreechart
- windows - 在 Windows 机器中远程(通过 ssh)移动光标
- c# - 如何在实体框架或 SQL Server 中获取分层数据
- signalr - SignalR 连接池
- algorithm - Raycast 玩家到网格交点的距离
- html - css悬停div闪烁
- javascript - reactjs中的切换按钮失败
- mysql - Mysql 之间使用,Unix 时间戳
- javascript - 如何在服务器端而不是客户端的 JAVA 中逐行读取 config.properties 文件中的数据
- php - 在jquery中循环ajax响应