简体   繁体   中英

Only user show his data rules firebase database

enter image description here

So what do I keep the rules of firebase database

​{ "rules": { ".read": "auth != true", ".write": "auth != true" } }

When I keep these rules, my application gets an error in addition to the image above

So what do I do if this error occurs

if you would like to only show the users document to the user that it belongs to you will need to have a reference to the user ID in said document for example

-Users
    --jfkdsfsadfasfsda(users ID)
        ---userID: jfkdsfsadfasfsda
        ---username: Mike Oxlong
    --gfhfdghfdfgdhfdgfd
        ---userID: gfhfdghfdfgdhfdgfd
        ---username: Tess Tickle

and your rules would look like this

service cloud.firestore {
match /databases/{database}/documents {


 match /users/{userID} {
  allow read: if true;
  allow update, delete: if request.auth.uid == userID;
  allow create: if request.auth != null;
 }

this will allow tess to read mikes user data but not edit or delete it however allowing tess to edit her own data. also it only allows registered users to create data.

https://youtu.be/eW5MdE3ZcAw - this video is super helpful

Happy Coding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM