1

I know that it is a common question but I did not find my question along the previous ones.

I have created a new firebase project and I am trying to work with it. I have created public so everybody can actually work with:

Permissions

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

But when I have tried to post one object I have gotten an error:

Error: Uncaught (in promise): Error: PERMISSION_DENIED: Permission denied Error: PERMISSION_DENIED: Permission denied

How could not I have permissions if the database is currently public? How could I solve it?

My code is pretty simple:

Object

export class Coordenate {
  $key: string;
  latitude: number;
  longitude: number;
}

Typescript component

onAddMarker(event) {
    this.databaseService.postCoordenate(event.coords.lat, event.coords.lng);
    //this.latitude = event.coords.lat;
    //this.longitude = event.coords.lng;
  }

Service

listToStore: AngularFireList<any>;

//Insert a new bet
  postCoordenate(latitude, longitude) {
    this.listToStore = this.db.list("coordenates");
    //Get the value of the photo URL in subscribe
    this.listToStore.push({
      latitude: latitude,
      longitude: longitude
    });
  }

The firebaseConfig is add to my environment in my angular project

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
bellotas
  • 2,349
  • 8
  • 29
  • 60
  • 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 Feb 23 '19 at 15:46

1 Answers1

4

This is because your rules are public for firebase cloud firestore but you are trying to write data to firebase realtime database. Select firebase realtime database and apply the following rules:

{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
   "rules": {
      ".read": true,
      ".write": true
    }
}
Balaj Khan
  • 2,490
  • 2
  • 17
  • 30