简体   繁体   中英

firebase delete specific item from Realtime Database

在此处输入图像描述 don't know how to make user abele to delete his own comment in android studio using java

all comments played at list

need user to press button delete to delete his comment

and no one can delete comment not his

[![this is my data structure] 在此处输入图像描述

Solution1: Add a user's uid in the comment. Use that uid to match the current logged-in user's uid to show delete button in your UI. data structure for comments: [{uid, name, photoUrl, rating, text}]

Solution2: The above way should work but essentially all users had delete access to anyone's comment.. it's just that you're not showing the mechanism in UI. for better security I guess you should look at https://firebase.google.com/docs/database/security something like should work

{
  "rules": {
    "items": {
      "$item_id" : {
        "comments": {          
          "$comment_id": {            
            ".read": "auth != null",
            ".write": "auth != null && (data.child('uid').exists() ? (data.child('uid').val() == auth.uid) : true)"
          }
        }
      }
    }
  }
}

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