且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase-提取用户时权限被拒绝

更新时间:2022-11-16 09:04:32

鉴于您当前的安全规则,您只授予当前用户访问其自己节点的权限.

Given your current Security rules you are only giving permission to your current user to access only its own node.

如果要制作动态图片,请尝试制作另一个父节点,其中包含您想与其他用户共享的详细信息.

If thats the dynamic you want to go by try making another parent node which contains the details that you would wanna share with other users.

users:{
 userID1 : {../*PERSONAL DETAILS*/},
 userID2 : {../*PERSONAL DETAILS*/},
 userID3 : {../*PERSONAL DETAILS*/},
 userID4 : {../*PERSONAL DETAILS*/},
 userID5 : {../*PERSONAL DETAILS*/},
 ....
  },
USERS_INFO: {
  userID1 : {../*Details to share*/},
  userID2 : {../*Details to share*/},
  userID3 : {../*Details to share*/},
  userID4 : {../*Details to share*/},
  userID5 : {../*Details to share*/},
  ....
  }

并将您的安全规则更新为:-

And update your security rules to:-

 {
 "rules": {
 "users": {
   "$uid": {
     ".read": "$uid === auth.uid",
     ".write": "$uid === auth.uid"
   }
  },
  "USERS_INFO":{
     ".read" : "auth != null",
     ".write" : "auth != null"
    }
  }
 }

查询类似:-

 FIRDatabase.database().reference().child("USERS_INFO").observe(.childAdded, with: { (snapshot) in