0

I have a user node that looks like this:

name:    "someone"
isAdmin: true
isDev: true
permissions:
  shots: true

Ultimately, I would like to grant anyone who is an admin to read and write to anything.

but in the meantime, how do I check a users permissions and then grant access?

Something like so:

match /{document=**} {
  allow write: if request.user.permissions.shots == true;
} 

UPDATE:

I've gotten a little farther.

allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.permissions.shots == true;

I feel like should work, because what is below does work:

allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.name == 'someone';

UPDATE:

As I dig deeper the approach below seems like the correct direction, but still not working

allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.permissions2.child('shots').val() == true;
ss_matches
  • 497
  • 2
  • 5
  • 20
  • The rules you shared are for Cloud Firestore, yet you tagged with `firebase-realtime-database`. While the two databases are both part of Firebase, they are quite different and security rules for one don't apply to the other. If you are indeed using the Firebase Realtime Database, see my answer here for how to edit the corresponding security rules: https://stackoverflow.com/a/52129163 – Frank van Puffelen Sep 22 '18 at 02:09
  • @FrankvanPuffelen My apologies. I removed the tag, I am looking for guidance on Cloud Firestore. Thank you – ss_matches Sep 24 '18 at 14:10
  • @FrankvanPuffelen Curious if you can provide some input on this in regards to my updates – ss_matches Oct 04 '18 at 20:00

1 Answers1

0

So, it turned out I was making it harder than it had to be.

If I just omitted

== true

it would have worked. I thought that was the first thing I tried, but oh well

allow write: if currentUser().permissions.shots || currentUser().isAdmin;

FYI, in addition to that I added a function to DRY it up

function currentUser() {
        return get(/databases/$(database)/documents/users/$(request.auth.uid)).data;
    }
ss_matches
  • 497
  • 2
  • 5
  • 20