skip to Main Content

Receiving this error when trying to read from my firebase firestore collection. It’s a public read only collection

E/flutter ( 2038): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

Here’s my security rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /trainers {
      allow read : if true;
    }
  }
}

I’ve also tried setting the rules like this

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /trainers {
      allow read;
    }
  }
}

My query

firebaseDb.collection("trainers").get().then((value) => {
  print(value)
});

main func

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  setSystemOverlay(getIsDarkMode());

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  runApp(const MyApp());
}

3

Answers


  1. Chosen as BEST ANSWER

    I managed to find the solution, the rules syntax needs to be like so

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /trainers/{document=**} {
          allow read, write;
        }
      }
    }
    

  2. Try changing your security rules to the following:

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if true;
        }
      }
    }
    
    Login or Signup to reply.
  3. Not works, I’m use Flutter StreamBuilder and my rules in Firestore

    But, before works, I don’t touch enythink only live to works, sorry my english is bad.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search