0

I have implemented rules in Firebase to restrict access to the data and when I simulate read / write priviledges in the Firebase Validator view the permission is granted. But when I run through VueFire no results are returned.

This is the structure of the database:

<firebase-id>:
   -chat:
     -messages:
       - message1
       - message2
       - message3

This is my rules from Firebase:

{
 "rules": {
 "chat": {
    "messages": {
       "$message": {
          ".read": "auth != null && data.child('uid').val() == auth.uid",
          ".write": "auth != null && data.child('uid').val() == auth.uid"
         }
       }
     }
   }
}

I am logged in and authenticated, but i receive no results.

I have tried to grant access when authenticated which works when i put the rule on the chat level, messages level, but not if i put it on the $message level, which indicates that VueFire has trouble with the wildcards ($) ?

Has anyone else experienced something similar ? or have any ideas what is wrong?

Update: I found out that the validation fails when trying to access the array of messages, as I am trying.

Code snippet:

// Generate ref to messages fails validation
export const messages = firebaseRef.child('chat').child('messages');
// Generate ref to specifi message create by user passes validation
export const messages = firebaseRef.child('chat').child('messages').child('<message id>')

So access to this path is not granted, but only if i try to fetch one specific message. But how can i retrieve an array which only includes the items which passes the validation ?

tjaydk
  • 281
  • 3
  • 8
  • Please include the code and/or simulated values you are using to test this. – André Kool Aug 08 '18 at 13:46
  • [Query based security rules](https://firebase.googleblog.com/2018/01/introducing-query-based-security-rules.html) can be a solution. – André Kool Aug 08 '18 at 14:19
  • Thank you @AndréKool for your reply, looks interesting. I will give that a go before restructuring my database. – tjaydk Aug 08 '18 at 14:25

1 Answers1

0

After some more research i found out that what i tried to achieve is not possible in Firebase, so i have to restructure my database to achieve this behavior. For more information see link to another StackOverflow post: Firebase security rules for child items in arrays

tjaydk
  • 281
  • 3
  • 8