Home > Enterprise >  Create Normal users and Prenium users and constrain access firebase data with this groups in ionic a
Create Normal users and Prenium users and constrain access firebase data with this groups in ionic a

Time:06-28

I'm developing an app with Firebase and ionic, I would like to restrict access to posts in the app with the role of a user (Premium or Normal)

Example of my data in Firebase :

{"post1" : {"text": "hi all users", "access":["normal", "premium"]},
"post2": {"text": "hi premium users", "access":["premium"]}

How can I do it with real time dataset Firebase and ionic (Javascript)? What is the most secure way?

CodePudding user response:

to achieve that i have create rules in my realtime database with conditions to access it (one node in db for normal and one node in db for prenium) , and the condition to access it are verified with the informations in user db for the rules

{
  "rules": {
    "prenium": {
     ".read":"root.child('users').child(auth.uid).child('status_prenium').val() === true",
    },
     
    "normal": {
     ".read":"root.child('users').child(auth.uid).child('status_access').val() === true",
    },
}
  • Related