Back

Create Document Permission Array

  • 0
  • Self Hosted
  • React Native
  • Databases
Timm
8 Aug, 2024, 22:09

Hello everyone,

I am currently a little bit confused on how to define an array of Permissions that I can use in a database.createDocument() statement. I included a short code snippet to demonstrate my problem:

TypeScript
memberArray.forEach((member) = > {
  permissions.push(Permission.read(Role.user(member.userId)));
});
createDocument = await databases.createDocument(
    "<database>", "<collection>", ID.unique(), {data}, permissions);```

I've tried several different alternatives including mapping the array directly in the ```createDocument()``` function, or using an array of strings like ```read("user:<id>)```
Nothing seems to work, the error message is always the same: ```Error creating document: [AppwriteException: Permissions must be one of: (any, users, user:<censored>, user:<censored>/unverified, users/unverified)]```

I would be very very grateful if somebody could help me out, because I am starting to feel a little bit dumb 🥲
TL;DR
Developers are struggling to define an array of Permissions for a ```database.createDocument()``` statement. The error message keeps showing the permissions must be specific types, but they tried various alternatives without success. One solution is to use the correct Permission format like ```Permission.read(Role.user(member.userId))``` within the array.
Steven
8 Aug, 2024, 22:10

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Steven
8 Aug, 2024, 22:12

From the docs:

A project user can only grant permissions to a resource that they have. For example, if a user is trying to share a document with a team that they are not a member of, they will encounter a 401 not authorized error. If your app needs users to grant access to teams they're not a member of, you can create Appwrite Functions with a Server SDK to achieve this functionality.

Timm
8 Aug, 2024, 22:32

Thank you, I will give it a try.

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