Запрос Firestore не может получить документы - PullRequest
1 голос
/ 26 мая 2020

, поэтому у меня есть массив в коллекции под названием «Авторы». Я хочу проверить, есть ли определенная строка (почта), но в ней говорится, что в getDocuments отказано в разрешении. Вот небольшой фрагмент:

  List<String> authors;

  _getAuthors(DocumentSnapshot doc) async {
    if (await FirebaseAuth.instance.currentUser() != null) {
      var query = Firestore.instance
          .collection('mealList')
          .where('Authors', arrayContains: mail);
      query.getDocuments().then((value) => print(value));
    }
  }

  Widget buildItem(DocumentSnapshot doc) {
    DateTime now = doc.data['Date'].toDate();
    DateFormat formatter = DateFormat('dd-MM-yyyy');
    String formatted = formatter.format(now);
    _getUserId();
    _getMail(doc);
    if (doc.data['Authors'] != null) {
      _getAuthors(doc);
    }

А вот правила моей базы данных:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    match /mealList/{uid} {
      allow read, write: if request.auth == null;
    }

    match /shoppingList/{uid} {
      allow read, write: if request.auth != null;
    }
  }
}

Ответы [ 2 ]

0 голосов
/ 26 мая 2020

В foodList вы объявили правило как

match /mealList/{uid} {
      allow read, write: if request.auth == null;
    }

, которое не позволяет пользователям, которые имеют право читать, писать.

Поэтому попробуйте заменить это на:

match /mealList/{uid} {
      allow read, write: if request.auth != null;
    }
0 голосов
/ 26 мая 2020
   match /mealList/{uid} {
      allow read, write: if request.auth == null;
    }

should be 

   match /mealList/{uid} {
      allow read, write: if request.auth != null;
    }
...