Search code examples
firebasefirebase-realtime-databasefirebase-securityfirebase-console

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


Solution

  • 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.