0

I've been having these Permission Denied when testing firebase in my flutter project, and I can't figure it out. I'm using email authentication and it works in flutter. But after reading about this error in other posts, I tried to allow read , write for all in my security rules :

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

But I still get the same error:

W/RepoOperation(24227): setValue at /1_testing failed: DatabaseError: Permission denied
W/RepoOperation(24227): setValue at /2_testing failed: DatabaseError: Permission denied
E/flutter (24227): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(-3, Permission denied, , null)

My code for sending data is:


    final databaseReference = FirebaseDatabase.instance.reference();
    void createRecord(){
    databaseReference.child("1_testing").set({
    'title': 'It worked once',
    'description': 'blablibla'
    });
    databaseReference.child("2_testing").set({
    'title': 'it worked twice',
    'description': 'blobloblo'
    });

I also re-downloaded and sync my json file Do you have any ideas ? It's the first time I'm trying this so sorry in advance if the answer seems obvious :/

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
juloni
  • 45
  • 8
  • The security rules you're showing apply to Cloud Firestore, while the code you're showing is accessing the Realtime Database. While both databases are part of Firebase, they're completely separate, and the security rules for one don't apply to the other. To fix the error, you will have to set the rules for the Realtime Database. For a walkthrough of how to do that, see https://stackoverflow.com/a/52129163 – Frank van Puffelen Nov 09 '20 at 21:30

1 Answers1

2

Those are the rules for firestore:

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

while in your code you are using the realtime database. You need to navigate to the realtime database tab in the console and update the rules to the following:

{
  // Allow read/write access to all users under any conditions
  // Warning: **NEVER** use this ruleset in production; it allows
  // anyone to overwrite your entire database.

  "rules": {
    ".read": true
    ".write": true
  }
}    

Read more about it here:

https://firebase.google.com/docs/rules/insecure-rules#database

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134