xrep
xrep

Reputation: 195

Firebase Security Rules -> prevent delete, write as unauthorized

I am trying to set Firebase security rules as:

The structure of the database is:

<db_name>
  users
    -L09I7kaAYExzzxB3N82 // this is unique ID generated by push()
    ....

My current rules are:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth == null"
  }
}

How to set it up?

Thanks!

Upvotes: 0

Views: 814

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599946

Something like this:

{
  "rules": {
    ".read": false,
    "users": {
      "$uid": {
        ".write": "newData.exists() && !data.exists()"
      }
    }
  }
}

I'd recommend reading the Firebase documentation, specifically the section on new data vs existing data.

Upvotes: 0

Related Questions