Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安全地处理两个用户';Firebase'中的通用信息;s Firestore,耦合器ID.contains下的红色箭头(request.auth.uid)_Firebase_Google Cloud Firestore_Firebase Authentication_Firebase Security - Fatal编程技术网

安全地处理两个用户';Firebase'中的通用信息;s Firestore,耦合器ID.contains下的红色箭头(request.auth.uid)

安全地处理两个用户';Firebase'中的通用信息;s Firestore,耦合器ID.contains下的红色箭头(request.auth.uid),firebase,google-cloud-firestore,firebase-authentication,firebase-security,Firebase,Google Cloud Firestore,Firebase Authentication,Firebase Security,我需要在Firebase中存储关于2个用户的信息,这些信息需要适当保护,以防其他用户读取 例如: user1: 'Adam' user2: 'Eve' commonInfo: meetingDate: new Date(-600000,1,1) marriageDate: new Date(-300000,1,1) children:['users/Cain','users/Abel','users/Seth'] (我猜亚当和夏娃现在已经买了一部智能手机,谁知道谁会使用

我需要在Firebase中存储关于2个用户的信息,这些信息需要适当保护,以防其他用户读取

例如:

user1: 'Adam'
user2: 'Eve'
commonInfo:
    meetingDate: new Date(-600000,1,1)
    marriageDate: new Date(-300000,1,1)
    children:['users/Cain','users/Abel','users/Seth']
(我猜亚当和夏娃现在已经买了一部智能手机,谁知道谁会使用这个应用程序……)

问题是我需要以一种简单而健壮的方式保护Firebase

我还需要考虑到一个用户一生中可能有几个伴侣

1/重复信息

我的第一个想法是使用云功能在两个用户配置文件之间同步数据。 只有当两个合作伙伴都有一个“with:”以对方为目标时,云功能才会运行

user1: 'Adam'
commonInfo:
    with: 'users/Eve' 
    meetingDate: new Date(-600000,1,1)
    marriageDate: new Date(-300000,1,1)
    children:['users/Cain','users/Abel','users/Seth']


user2: 'Eve'
commonInfo:
    with: 'users/Adam'
    meetingDate: new Date(-600000,1,1)
    marriageDate: new Date(-300000,1,1)
    children:['users/Cain','users/Abel','users/Seth']

那么Firestore规则就非常简单了:

match /users/{userId} {
      allow read, update, delete: if request.auth != null && request.auth.uid == userId;
      allow create: if request.auth != null;
    }
但我不太喜欢复制数据

2/名为afted用户ID的通用文档

如果有一份共同文件,会更经济

couple:EveAdam
    meetingDate: new Date(-600000,1,1)
    marriageDate: new Date(-300000,1,1)
    children:['users/Cain','users/Abel','users/Seth']
我写了这封信,但我在对联ID下有两个红色箭头,包含:

注意:包含按照以下要求使用的内容:


我是firebase的新手,不知道这是否有效,也不知道这是否是一种很好的方法…

正如@DougStevenson和我在评论中提到的,最好的方法是在多个文档中复制数据,原因如下:

  • 数据复制是NoSQL数据库的常见做法,有时也是推荐做法

  • 对于firebase规则中包含的当前逻辑,第二种方法是不可能的,而将两个uid串联存储本身就是一种数据复制形式


安全规则本身根本不起任何作用。如果您提供规则应允许或拒绝的特定客户机查询,则更容易考虑这些查询。还要知道,在nosql类型的数据库中,复制数据非常常见。在许多情况下,您应该会认为这是首选选项。我认为最好的选项是复制信息,因为这是Firestore和Doug所介绍的其他nosql数据库中的常见做法,而且,在firebase规则中,该
包含的
逻辑不可能按照您打算的方式执行,因此您可能必须在文档本身中将两个用户ID分开,这也是一种重复。让我知道这是否有帮助。
match /couples/{CoupleId} {
      allow read, update, delete: if request.auth != null && coupleId.contains(request.auth.uid);
      allow create: if request.auth != null;
    }