Skip to content

Instantly share code, notes, and snippets.

@belachkar
Last active August 7, 2022 23:27
Show Gist options
  • Save belachkar/7be57e587fded0ad322abf781f75e407 to your computer and use it in GitHub Desktop.
Save belachkar/7be57e587fded0ad322abf781f75e407 to your computer and use it in GitHub Desktop.

Firebase Configurations

Examples for Firebase configurations.

Cloud Store

Example 1

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /guestbook/{entry} {
      allow read: if
        request.auth.uid != null;
      allow create: if
        request.auth.uid == request.resource.data.userId
        && "name" in request.resource.data
        && "text" in request.resource.data
        && "timestamp" in request.resource.data;
      allow update: if
        request.auth.uid == resource.data.userId
        && "name" in request.resource.data
        && "text" in request.resource.data;
      allow delete: if
        request.auth.uid == resource.data.userId;
    }
    match /attendees/{userId} {
      allow read: if true;
      allow create, update: if
        request.auth.uid == userId 
        && "attending" in request.resource.data;
      allow delete: if
        request.auth.uid == userId;
    }
  }
}

Example 2

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /carts/{cartID} {
      allow create: if
        request.auth.uid == request.resource.data.ownerUID;
      allow read, update, delete: if
        request.auth.uid == resource.data.ownerUID;
    }
 
    match /carts/{cartID}/items/{itemID} {
      allow read, write: if
        get(/databases/$(database)/documents/carts/$(cartID)).data.ownerUID == request.auth.uid;
    }
 
    match /items/{itemID} {
      allow read, create;
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment