Home > database >  Flutter Firestore permission denied
Flutter Firestore permission denied

Time:01-03

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());
}

CodePudding user response:

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;
    }
  }
}

CodePudding user response:

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;
    }
  }
}
  • Related