In firebase realtime database our users have a custom claim called premium this claim can have three values LEVEL_1 , LEVEL_2 or REGULAR my database rules are:
{
"rules": {
".read": "auth.token.admin === true",
".write": "auth.token.admin === true",
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid",
"Boxes":{
"Manual":{
".read": "auth.token.premium === 'REGULAR'",
".write": "auth.token.premium === 'REGULAR'",
}
}
},
}
}
But I want to say if premium value is REGULAR only allow read/write for 5 records and if it is LEVEL_1 only 20 records and for LEVEL_2 access to all records and if we change from LEVEL_1 to REGULAR for example the rules do not remove records and just don't allow write more and allow for read 5 records.