I cant seem to get these rules to work keep giving error on line 19

25 views
Skip to first unread message

MarKevis Williams

unread,
Jun 4, 2024, 4:18:18 AMJun 4
to Firebase Google Group
{
  "rules": {
    ".read": "auth != null", // Make sure to restrict access to authenticated users for other paths not mentioned explicitly

    "events": {
      ".read": true,  // Anyone can view events
      ".write": "auth != null",  // Only authenticated users can create or attend events
      "$eventId": {
        // Allow event creation for authenticated users
        ".write": "auth != null && (!data.exists() || data.child('createdBy').val() == auth.uid)",

        // Restrict updates and deletes to the event creator
        ".validate": "newData.hasChildren(['name', 'date', 'createdBy'])",
        "createdBy": {
          ".validate": "newData.isString() && newData.val() == auth.uid"
        },

        // Only the event creator can edit or delete the event
        ".write": "auth != null && (data.exists() ? data.child('createdBy').val() == auth.uid : true)",

        // Logic for attending events (attendees will be stored in an array or map)
        "attendees": {
          "$userId": {
            // Only the user can add or remove themselves from the attendees list
            ".write": "auth != null && $userId == auth.uid"
          }
        },

        // Define nested chatroom for each event
        "chatroom": {
          "$messageId": {
            ".read": true,  // Anyone can read chat messages
            ".write": "auth != null",  // Only authenticated users can post messages
            "user": {
              ".validate": "newData.isString() && newData.val() == auth.uid"
            },
            "message": {
              ".validate": "newData.isString() && newData.val().length > 0"
            },
            // Only the message poster can edit or remove their message
            ".write": "auth != null && (data.exists() ? data.child('user').val() == auth.uid : true)"
          }
        }
      }
    }
  }
}
Reply all
Reply to author
Forward
0 new messages