Alok Kumar
Alok Kumar

Reputation: 114

Specific Firebase Rules

I'm using firestore as an API endpoint for an app for an event and need to be able to write data for a collection. How do I write the rules?

There's no authentication for the app (it's completely public) so I've tried the following rules:

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

    // Need to be able to write documents into the silent_disco collection
    match /databases/silent_disco/documents {
    match /{document=**} {
            allow write: if true;
        }
    }

    // Need to be able to write into the passport collection
    match /databases/passport/documents {
    match /{document=**} {
            allow write: if true;
        }
    }
}

When I use the simulated I can read everything as expected but write requests are denied.

Upvotes: 0

Views: 38

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83183

The following should work:

service cloud.firestore {
    match /databases/{database}/documents {

        match /{document=**} {
           allow read: if true;
        }

        // Need to be able to write documents into the silent_disco collection
        match /silent_disco/{docId} {
            allow write: if true;
        }

        // Need to be able to write documents into the passport collection
        match /passport/{docId} {
            allow write: if true;
        }

    }
}

You may watch the excellent official video on the subject: https://www.youtube.com/watch?v=eW5MdE3ZcAw

Upvotes: 1

Related Questions