Back

[SOLVED] Getting error when setting permission of a document during its creation

  • 0
  • Databases
  • Accounts
nightwielder
19 Apr, 2023, 14:36

Hi! Following is my code:

TypeScript
await databases.createDocument(
  'DB_ID',
  'COLLECTION_ID',
  user.$id,
  {
    name: user.name,
    age: 20,
    college: 'Harvard'
  },
  [Permission.update(Role.user(user.$id))]
);```

But I'm getting this error: `AppwriteException: Permissions must be one of: (any, guests)`. Any idea what's up? Note that, I'm creating the account immediately before this, with `user = await account.create(...)`
TL;DR
The user is getting an error when trying to set permissions for a document during its creation. The solution is to make sure that the attributes of data for the documents have been created in the appwrite console. Additionally, document level permissions need to be enabled and users should be allowed to create documents. To fix the error in the code, change `[Permission.update(Role.user(user.$id))]` to `[Permission.update() or Permission.update(Role.guest())]`.
joeyouss
19 Apr, 2023, 16:11

Hi - let me take a look and brb

joeyouss
19 Apr, 2023, 16:19

You need to enable document level permissions and allow user to create documents.

When you create the document, you can put yourself for update access so you can update.

The error in your original post is occurring because you're not authenticated

Berserker
19 Apr, 2023, 17:44

@nightwielder make sure that u have also Created the attributes of data for the documents in the appwrite console

nightwielder
21 Apr, 2023, 06:33

[SOILVED]Getting error when setting permission of a document during its creation

nightwielder
21 Apr, 2023, 06:33

[SOLVED] Getting error when setting permission of a document during its creation

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