Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase/Database - Version 2 Security Rules?

I'm just getting started with Firebase, and notice that there are a lot of tutorials/docs that instruct you to put the following into the rules for your database:

{
  "rules": {
    "$uid": {
      ".write": "$uid === auth.uid",
      ".read": "$uid === auth.uid"
   }
 }
}

However, there seems to be a new version of this code out, version 2. I was wondering if the code I have above, which is outdated and version 1 (I guess), is essentially equivalent to this code:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

which comes from the google firebase docs (https://firebase.google.com/docs/firestore/security/get-started)

Thanks

like image 837
Evan Avatar asked Dec 24 '19 23:12

Evan


1 Answers

You're showing rules from two different products that aren't directly related to each other.

Your first sample is for Firebase Realtime Datbase. That JSON-based rules language hasn't changed in years.

Your second sample is for Firestore. That's a completely different security rules language that's a little bit similar to, but not at all the same as, Firebase Realtime Database.

The rules "version 2" you're referring to is for Firestore only. It changes the behavior of a couple aspects of the language, and that's all.

like image 72
Doug Stevenson Avatar answered Nov 15 '22 11:11

Doug Stevenson