Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I ban a User in Firebase realtime Database using the rules?

I’ve created a list of banned users in my realtime Database and I want to make them impossible to log-in, I know I can use the database rules, but I don’t know how, can someone help me?

This is my database structure:

/banned-users:
    /UserId1:True
    /UserId2:True

Those are my database rules:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    {
    "rules": {
    ".read": true,
    ".write": true
      }

   }

>Solution :

You need to reference data in other paths as follows:

{
  "rules": {
    "thepath": {
          ".read": "root.child('banned-users').child(auth.uid).val() !== true"
          ".write": "root.child('banned-users').child(auth.uid).val() !== true"
      }
    }
}

Note that actually you don’t "make them impossible to log-in", because this is not possible, but you prevent them writing to/reading from your database.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading