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:
What is the problem? How can I solve it?
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;
}
}
}