Home > OS >  How to acces firebase data using a key
How to acces firebase data using a key

Time:10-23

I want to secure my firestore data. I have an app that accesses the data from firestore. Currently, my rules allow anyone to read and write. How can I access the data using a key I have in the app? Sort of verify a key before anyone can read or write data.

Here are my current rules:

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

https://gyazo.com/da26189ac1c5bbdea8d374ad8870bd7f - this is why I am asking

CodePudding user response:

The security rules of your Firestore database only have access to:

  • The path that is being accessed (read or written).
  • The data that is being written.
  • The token of the user that is accessing the data.
  • Other data in the database.

There is no way to pass custom data to the security rules in another way, so anything you need will have to be in one of these.

So if you want to pass custom data in both read and write operations, you'll have to do so in either the path or make it part of the user's token, for example by setting a custom claim in there.

Also see:

  • Related