0

I have a firestore collection like this:

  • raffle-holder
    • {uid}
      • games
        • {game}
          • {game data}
      • user
        • data
          • {user data}
      • {raffle-holder data}

My current security rules are as follows:

match /raffle-holder/{uid} {
  allow read: if request.auth.uid == uid;
  
  match /games/{document=**} {
    allow read, write: if request.auth.uid == uid;
  }
  
  match /user/data {
    allow read,write: if request.auth.uid == uid;
  }
}

I tried the rule simulator with one of my authenticated users and it works fine, but when I try to get data from /raffle-holder/{uid}/games/{game} then I get a Missing or insufficient permissions error. Also, I verified that my variables are correct and need help debugging why this error is appearing.

void getUserTixs() {
  final userId = FirebaseAuth.instance.currentUser!.uid;
  final gameRef = db
    .collection("raffle-holder")
    .doc(userId)
    .collection("games")
    .doc(widget.gameId);
  gameRef.get().then((value) {
    if (value.exists) {
      gameRef.snapshots().listen((event) {
        if (event.data() != null) {
          setState(() {
            userTixs = event.data()!['tixPurchased'];
          });
        }
      });
    }
  }, onError: (e) {
    print(e);
  });
}
JGTechie
  • 55
  • 6
  • It's uncertain from the code you shared whether `currentPlayer.uuid` matches the value of `request.auth.uid` in your rules. Consider passing `firebase.auth().currentUser.uid` directly. – Frank van Puffelen Jan 18 '23 at 00:28
  • Tried your suggestion and received same error – JGTechie Jan 18 '23 at 00:44
  • Thanks for trying. Can you show the updated code of what you tried in your question, so that we can clean up these comments and others won't have to wonder the same thing? – Frank van Puffelen Jan 18 '23 at 01:22
  • Along with the above suggestions, also check the following links: [Writing Rules](https://firebase.google.com/docs/firestore/security/get-started#writing_rules) , https://stackoverflow.com/questions/67688203/firestore-firebaseerror-missing-or-insufficient-permissions, https://stackoverflow.com/questions/68185135/uncaught-error-in-onsnapshot-firebaseerror-missing-or-insufficient-permissions, https://stackoverflow.com/questions/49306209/error-missing-or-insufficient-permissions – Vaidehi Jamankar Jan 18 '23 at 09:42

0 Answers0