首页 > 解决方案 > Firestore 中的组查询设置规则中的问题(错误代码=PERMISSION_DENIED)

问题描述

我很确定,我正在尝试通过谷歌控制台设置 firestore 规则我在颤振中使用组查询,但我得到了同样的错误

我有 Notes(collection)-> CSC(DOC) ->sem1(collection) ->(doc)->subject1="主题值 (field) | |->ECE(DOC) ->sem1(collection) -> (doc)->subjectece="the value of subject ece of subject" (field)

我的数据库 1

我的数据库在 1 个集合上

我的数据库在 1 个子集合上

我的规则

我的错误:

W/Firestore(16933): (22.1.2) [Firestore]: Listen for Query(target=Query( collectionGroup=Notes order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}

E/flutter (16933): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
E/flutter (16933):

我曾尝试对 Firestore 规则进行 20 多次更改但同样的错误:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
   match /calculatorApp/{userId} {
      allow read :if request.auth != null&& request.auth.uid == userId;
      allow create: if request.auth != null;
      allow delete: if request.auth != null && request.auth.uid == userId;
        allow write:if request.auth != null && request.auth.uid == userId;
      allow  update:if request.auth != null &&request.auth.uid == userId;
    }

   match /{path=**}/Admin/{documents}{
      allow read, write: if false;

    } 
   match /{path=**}/subsettings/{subsettingsId}{
       allow read, write: if false;
    }
 match /{path=**}/notes/{notesId} {
      allow read, write: if false;

    } 
   match /{path=**}/sem1/{sem1Id} {
       allow read, write: if false;
    }
    

  }
}

我的颤振代码:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

class Testdb extends StatefulWidget {
  @override
  _TestdbState createState() => _TestdbState();
}

class _TestdbState extends State<Testdb> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: IconButton(
              icon: Icon(Icons.ac_unit),
              onPressed: () async {
                FirebaseFirestore.instance
                    .collectionGroup("Notes")
                    .snapshots()
                    .listen((value) => value.docs.forEach((element) {
                          print(" ELEMENT  ${element.id}");
                          print(" ELEMENT  ${element.data()}");
                   ;
                        }));
              })),
    );
  }
}

伙计们请帮助我是初学者,也是firestore的新手,我在firestore的设定规则内遇到了问题

标签: firebasefluttergoogle-cloud-firestorefirebase-security

解决方案


推荐阅读