f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

PlatformException(Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions., null) #59

Closed zeeshantasleem closed 3 years ago

zeeshantasleem commented 3 years ago

No error in my Dart Code, but I cannot write data to firestore, Error is as Below::

Code Snippet: `abstract class Database { Future createReport(Map<String, dynamic> reportData); }

class FirestoreDatabase implements Database{ FirestoreDatabase({@required this.uid}) : assert (uid!=null); final String uid;

//TODO: to create a report hard coded: Future createReport(Map<String, dynamic> reportData) async { final path = 'user/$uid/reports/reports_1'; final documentReference = Firestore.instance.document(path); await documentReference.setData(reportData); } }`

void _createReport(BuildContext context) { final database = Provider.of<Database>(context); database.createReport({ 'crime Type' : 'Blogging', 'Description' : 'description needs to be provided', }); }

`class Report{ Report({@required this.crimeType, @required this.description}); final String crimeType; final String description;

//TODO: to map data to Firestore

Map<String, dynamic> toMap(){ return{ 'CrimeType' : crimeType, 'Description': description, }; } }`

Firebase Rules: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /users/{uid}/Reports/{document=**} { allow read, write; }}}

zeeshantasleem commented 3 years ago

I have solved this, and for others to get help.. Here is the solution:

Try Changing your Firebase Rule to: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /users/{uid}/Reports/{document=**} { allow read, write: if true; } } }

if this does not work then try this: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if true; } } }