Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – Firebase security rules multiple queries needed to get children

Posted on November 14, 2022

Solution 1 :

Security rules don’t filter data. So that means that in your current data model you indeed have to perform two read operations.

The common solution is to separate the public and “slightly less” public settings into two top-level nodes:

"Settings":{ 
    ".read": "auth != null",
    ".write": "root.child('Users').child(auth.uid).child('rank').val() == 3",
},
"PublicSettings":{ 
    ".read": true,
    ".write": "root.child('Users').child(auth.uid).child('rank').val() == 3",
},

Now all users will have to perform two reads, one for the auth-requiring settings and one for the public settings. But it will now require two reads, no matter how many public properties you define.

Problem :

there is a table called Settings in my database and in my security rules, only two of the children can be accessed by non auth user.

  "Settings":{ 
    ".read": "auth != null",
    ".write": "root.child('Users').child(auth.uid).child('rank').val() == 3",
    "$id":{
      ".read": "$id == 'maintenance' || $id == 'welcomeList'"
    }
},

But this way I can not get settings using one query like below:

settingsRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        settings = dataSnapshot.getValue(Settings.class));
    }
});

I have to query twice to get what I want. Is there any other way to do this? Because I am going to need more than two children in the future and I do not want to end up having 5 different queries.

settingsRef.child("maintenance").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        settings.setMaintenance(dataSnapshot.getValue(Integer.class));
    }
});

settingsRef.child("welcomeList").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {              
         settings.setWelcomeList(dataSnapshot.getValue());
    }
});

Comments

Comment posted by jackieboyx

Thank you for your answer. In this case the solution you’ve suggested seems fine. But for example, I have questions in my database and I can not let the users see the answer. But when i set it to false, they won’t have a permission to check if it is wrong or right. So i set it to “auth != null” and now they have access to the answer. What I am afraid of is if they can find a way to access the answer outside the application, or hack into it or something. I don’t know if i managed to explain my issue but again thanks for the solution.

READ  [ANSWERED] Android faild build the project (Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.CharStreams)
Powered by Inline Related Posts

Comment posted by jackieboyx

I don’t have the reputation to vote but thank you for your help.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress