0

When the user creates an account his information will be saved on my realtime database. Something like this:

{
  username: "geroge",
  plan: "free",
  email: "georgeo@example.com",
}

And I don't want to let the user change this information. So this is my question how can I set up the rules so that the user is allowed to write the data to the database only once? Basically when he writes the data to the database the first, he can't change them anymore.

I've tried a couple of times to do this, but I didn't succeed this is are my rules:

{
  "rules": {
    ".read": "true", 
    ".write": "false",  
    "users": {
      "$uid": {
        ".write": "$uid === auth.uid && !data.parent().exists()",
        ".read": "$uid === auth.uid"
      }
    }
    }
  
}

I've tried to do something with write and check values exists, but it didn't work.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
timnik
  • 11
  • 2
  • 1
    Have you tried `!data.exists()`? Also can you share the code that you are using to update data and the operation is allowed ? – Dharmaraj Sep 15 '22 at 17:41
  • Yup, @Dharmaraj is correct: you'll want to check whether `!data.exists()` either in `.write` or in a `.validate` rule. – Frank van Puffelen Sep 15 '22 at 18:00

0 Answers0