Back

Understanding Permissions: Read error when a collection has "any" can "read"

  • 0
  • React Native
  • Cloud
andreaselia
13 Oct, 2024, 20:26

Heya,

I'm messing around with RN and Cloud hosted Appwrite at the moment, and have run into an issue with permissions.

I get the error "The current user is not authorized to perform the requested action" when trying to read all documents in a collection.

The collection has the permission "any" and "read", so I'm not entirely sure where I'm going wrong here.

Here's my collection setup:

TypeScript
{
    "$id": "66f541aa0039ba252fa9",
    "$permissions": [
        "read(\"any\")"
    ],
    "databaseId": "66f4877d00384273b485",
    "name": "Questions",
    "enabled": true,
    "documentSecurity": false,
    "attributes": [
        {
            "key": "question",
            "type": "string",
            "required": true,
            "array": false,
            "size": 200,
            "default": null
        },
        {
            "key": "entries",
            "type": "relationship",
            "required": false,
            "array": false,
            "relatedCollection": "66f487b700228e45ca0f",
            "relationType": "manyToOne",
            "twoWay": true,
            "twoWayKey": "questions",
            "onDelete": "cascade",
            "side": "child"
        }
    ],
    "indexes": []
}

I do not have "database security" enabled, but from my understanding, it doesn't need to be?

My code (slimmed down) is essentially:

TypeScript
const client = new Client();

client
  .setEndpoint(appwriteConfig.endpoint)
  .setProject(appwriteConfig.project)
  .setPlatform(appwriteConfig.platform);

const account = new Account(client);
const databases = new Databases(client);

const questions = await databases.listDocuments(
  appwriteConfig.databaseId,
  appwriteConfig.questionsCollectionId
);
TL;DR
Issue: Developer is receiving an authorization error when trying to read all documents in a collection despite setting permission to "any" and "read". Solution: The issue could be with the way the permissions are set in the collection JSON. Double-check the permission format and make sure that database security is not causing any conflicts. Additionally, ensure that the user has the necessary permissions in Appwrite.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more