Skip to content

Firestore security rule issue #1828

@dancornilov

Description

@dancornilov

Version info

Angular: 6.0.2

Firebase: 5.0.4

AngularFire: 5.0.0-rc.10

Which is my problem?
In firestore simulator action pass validation but in app show error with insufficient permissions.

Store collections and fields.
screen shot 2018-08-22 at 1 10 19 pm

This is simulation.
screen shot 2018-08-22 at 1 09 47 pm

This is my query:
this.resultCol = this.afs.collection('messages', ref => ref.where('orderId', '==', this.id).orderBy('created', 'desc') );

This is error:
screen shot 2018-08-22 at 1 15 56 pm

Question: Why in the firestore simulator is alright but in real action doesn't

Security rules:

service cloud.firestore {
  match /databases/{database}/documents {
    
 	match /users/{user} {
       allow create:  if request.auth != null;
    }
    match /messages/{message} {
    
    function isConvParticipant() {
      return request.auth.uid == request.resource.data.clientId || request.auth.uid == request.resource.data.ownerId;
    }
    
    function isLoggedAndExist() {
      return request.auth != null && exists(/databases/$(database)/documents/users/$(request.auth.uid));
    }
    
       allow get: if isLoggedAndExist();
       allow list: if isLoggedAndExist() && request.auth.uid == resource.data.clientId || request.auth.uid == resource.data.ownerId;
       allow create: if isLoggedAndExist() && isConvParticipant();
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions