Back

SOLVED: Update Document permissions fails: user_unauthorized

  • 0
  • Databases
  • Users
whataboutno13
18 Aug, 2023, 16:30

Hi there, I want a user to update a Document he has read, update and delete permissions to. Now until he is the only one having any permissions this call works fine:

TypeScript
Document result = await databases!.updateDocument(
        databaseId: AppConstants.privateEventsDatabaseId,
        collectionId: AppConstants.eventsCollectionId,
        documentId: event.id!,
        data: event.toJson(),
        permissions: event.appwritePermissions,
      );

The method event.appwritePermissions creates a List<String> looking like this:

TypeScript
permissions = [
  "read("user:648ade3b69d58f61c640")",
  "update("user:648ade3b69d58f61c640")",
  "delete("user:648ade3b69d58f61c640")",
  "read("user:64df7d4a4cb958d68e76")",
]

Which is the same I get from Appwrite.

Question is, why cant I update the permissions in this form?

The full error looks like this:

TypeScript
AppwriteException (AppwriteException: user_unauthorized, Permissions must be one of: (any, users, user:648ade3b69d58f61c640, user:648ade3b69d58f61c640/verified, users/verified) (401))
TL;DR
The user is trying to update document permissions in their app using the Appwrite SDK. They have a list of permissions in the form of `user:userID`, but they are getting a `user_unauthorized` error. The error message suggests that the permissions must be one of `(any, users, user:userID, user:userID/verified, users/verified)`. The user needs to modify their permissions list and use one of the allowable formats mentioned in the error message. Solution: Modify the permissions list to use one of the allowed formats mentioned in the error message, such as `users` or `user:userID`.
Binyamin
18 Aug, 2023, 16:32

A user can set permissions of a document to is own or users or any to set permission to other users you'll need to use the database server side SDK and you can do so using a function.

whataboutno13
21 Aug, 2023, 06:51

Ah okay, I thought a user with write permissions could set the permissions of other users too

whataboutno13
21 Aug, 2023, 07:03

SOLVED: Update Document permissions fails: user_unauthorized

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