MXC
MXC

Reputation: 700

Null Value Error when running firestore security rule

I am learning about firestore security rules and I cannot get my head around why my security rule is failing.

This is my data structure: enter image description here

This is the rule which I am trying to run:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    match /company/{company} {
      allow create, read, write, delete: if request.auth.uid != null && 
        get(/databases/$(database)/documents/developer/$(request.auth.uid)).data.is_admin == true             
    }
  }
}

This is my JSON payload from simulator:

{
  "uid": " sxTCUVtxcSSTIWicv7op10Cc3ff2",
  "token": {
    "sub": " sxTCUVtxcSSTIWicv7op10Cc3ff2",
    "aud": "test-123",
    "email": "",
    "email_verified": false,
    "phone_number": "",
    "name": "",
    "firebase": {
      "sign_in_provider": "google.com"
    }
  }
}

YOu can see the UID matches the developer documentID. This is the error which I receive.

Error running simulation – Error: simulator.rules line [6], column [73]. Null value error.

Please guide me on what am I doing wrong.

Upvotes: 2

Views: 1844

Answers (1)

Bob Snyder
Bob Snyder

Reputation: 38319

Your JSON payload from the simulator shows a leading space in the "uid":

"uid": " sxTCUVtxcSSTIWicv7op10Cc3ff2",  
        ^Remove this space

It should work after the space is removed from your simulator input.

Upvotes: 3

Related Questions