Home > other >  Dart Flutter Firebase FirebaseException ([cloud_firestore/permission-denied] The caller does not hav
Dart Flutter Firebase FirebaseException ([cloud_firestore/permission-denied] The caller does not hav

Time:03-21

I have the following code in my main.dart file:

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

  FirebaseFirestore firestore = FirebaseFirestore.instance;
  await firestore.collection("oneSignal").add(
    {
      "id": "testing"
    }
  );

When I run the codes, I get an error like this:

enter image description here

What is the problem? How can I solve it?


enter image description here


Apart from the main.dart file, I also have a file related to Firebase:

For Firebase, apart from the main.dart file, I also have a file called firebase_options.dart. It contains many IDs.

CodePudding user response:

In firebase security is handled by security rules, it's a tab in your firestore firebase console. Check there if your caller (authenticated or not authenicated) is able to do write operation into oneSignal collection

For authenticated

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /oneSignal/{signalId} {
        allow write: if request.auth != null;
    }
  }
}

For unauthenticated

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /oneSignal/{signalId} {
        allow write;
    }
  }
}
  • Related