Особые правила Firebase - PullRequest
       9

Особые правила Firebase

0 голосов
/ 08 января 2019

Я использую Firestore в качестве конечной точки API для приложения для события, и мне нужно иметь возможность записывать данные для коллекции. Как мне написать правила?

Для приложения нет аутентификации (оно полностью общедоступно), поэтому я попробовал следующие правила:

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;
        }
    }
}

Когда я использую смоделированный, я могу читать все как положено, но запросы на запись отклоняются.

1 Ответ

0 голосов
/ 08 января 2019

Должно работать следующее:

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;
        }

    }
}

Вы можете посмотреть отличное официальное видео по теме: https://www.youtube.com/watch?v=eW5MdE3ZcAw

...