Search code examples
firebase-realtime-databasefirebase-authenticationfirebase-security

How to make a multilevel condition rules in firebase?


I My rules allow the user to read and write data if the localId, but I want to add a condition with email verification, I found a line of code on the Internet, but I don’t know how to add it correctly:

{
  "rules": {
    ".read": false,
    ".write": false,
    "$localId": {
      ".read": "auth.uid === $localId",
      ".write": "auth.uid === $localId",
    }
  }
}

that is my rules

".read": "auth != null && auth.token.email_verified"

and this is what I found


Solution

  • Include the condition auth.token.email_verified == true for .read and/or .write!

    {
      "rules": {
        ".read": false,
        ".write": false,
        "$localId": {
          ".read": "auth != null && auth.uid === $localId && auth.token.email_verified == true",
          ".write": "auth != null && auth.uid === $localId && auth.token.email_verified == true",
        }
      }
    }