Mona Jalal
Mona Jalal

Reputation: 38275

Firebase Security Rules Correct Format

Are these rules in correct format? When I put them in Database Rules, I see red dashed lines which may indicate an error/warning but when I hover over it, I receive no feedback.

{
  "rules": {

    "users": {
      "$uid": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",
        // grants read access to any user who is logged in --&& auth.provider === 'password'
        ".read": "auth !== null"
      }
    },

    "usernames": {
      "$userName": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "root.child('usernames').child($userName).child('uid').val() == auth.uid || root.child('usernames').child($userName).child('uid').val() == null",
        // grants read access to any user who is logged in --&& auth.provider === 'password'
        ".read": "auth !== null"
      }
    },

    "following": {
      "$uid": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",
        // grants read access to any user who is logged in --&& auth.provider === 'password'
        ".read": "auth !== null"
      }
    },

    "followedBy": {
      "$fid": {
        "$uid": {
          // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
          ".write": "auth !== null && auth.uid === $uid",
          // grants read access to any user who is logged in --&& auth.provider === 'password'
          ".read": "auth !== null"
        }
      }
    }

  }
}

This is what I see: enter image description here

Upvotes: 1

Views: 696

Answers (2)

Mahmoud Abu Alheja
Mahmoud Abu Alheja

Reputation: 3668

To reformat your code rules and make it read able Just copy your rules and then go to JS cleaner and click claen Js re copy and past into your database rules

Upvotes: 3

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

I've seen those too. Pretty much as soon as I add an empty line.

I think the empty lines are just causing a false error indicator to show up.

Since nothing's failing (at least not for me as far as I can see), I wouldn't worry about them.

Upvotes: 1

Related Questions