javascript - how to set permissions in firebase firestore - Stack Overflow

$path = "firebase_auth.json";$config = array("projectId" => "XXXX",&quo

    $path = "firebase_auth.json";

    $config = array(
        "projectId" => "XXXX",
        "keyFile" => json_decode(file_get_contents($path), true)
    );
    $firestore = new FirestoreClient($config);
    $collectionReference = $firestore->collection('Channels');
    $snapshot = $collectionReference->documents().get();

Response of this code is

An uncaught Exception was encountered

Type: Google\Cloud\Core\Exception\ServiceException

Message: { "message": "Missing or insufficient permissions.", "code": 7, "status": "PERMISSION_DENIED", "details": [] }

Filename: /var/www/html/riglynx/vendor/google/cloud/Core/src/GrpcRequestWrapper.php

Line Number: 263

    $path = "firebase_auth.json";

    $config = array(
        "projectId" => "XXXX",
        "keyFile" => json_decode(file_get_contents($path), true)
    );
    $firestore = new FirestoreClient($config);
    $collectionReference = $firestore->collection('Channels');
    $snapshot = $collectionReference->documents().get();

Response of this code is

An uncaught Exception was encountered

Type: Google\Cloud\Core\Exception\ServiceException

Message: { "message": "Missing or insufficient permissions.", "code": 7, "status": "PERMISSION_DENIED", "details": [] }

Filename: /var/www/html/riglynx/vendor/google/cloud/Core/src/GrpcRequestWrapper.php

Line Number: 263

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jan 23, 2019 at 5:30 Keyur NimavatKeyur Nimavat 3,6353 gold badges15 silver badges19 bronze badges 1
  • It looks like you don't have permission to read Channels. See firebase.google./docs/firestore/security/get-started. The simplest (but least locked down) version is in the ALLOW ALL box of the second example on that page. – Frank van Puffelen Commented Jan 23, 2019 at 5:33
Add a ment  | 

2 Answers 2

Reset to default 3

check out Get started with Cloud Firestore Security Rules documentation. And see Writing conditions for Cloud Firestore Security Rules documentation.

One of the most mon security rule patterns is controlling access based on the user's authentication state. For example, your app may want to allow only signed-in users to write data:

service cloud.firestore {
  match /databases/{database}/documents {
    // Allow the user to access documents in the "cities" collection
    // only if they are authenticated.
    match /cities/{city} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

This should help you get started.

Reason you are getting the error is because you are not allowed to access documents of the collection called Channels.

In order to fix this, you have login to your console firebase. Navigate to Database > Under firestore database, you have to click on Rules.

Under rules, you can give permission as per your wish. If you want to give access to al the users then you can simple replace current code with the following code. (Not a good practice and not secure too)

service cloud.firestore {
 match /databases/{database}/documents {
  match /{document=**} {
    allow read, write;
  }
 }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745414029a4626662.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信