Back

Issue with write permission for all users

  • 0
  • React Native
  • Locale
  • Auth
hen
30 Sep, 2024, 15:53

I have a problem with creating new documents (uploading post with video, image and text in my case), for every user such error occurs: The current user is not authorized to perform the requested action

Object for currently logged user:

TypeScript
{"$collectionId": "collectionId", "$createdAt": "2024-09-30T15:02:13.903+00:00", "$databaseId": "databaseId", "$id": "id", "$permissions": ["read(\"user:accountId\")", "update(\"user:accountId\")", "delete(\"user:accountId\")"], "$updatedAt": "2024-09-30T15:02:13.903+00:00", "accountId": "accountId", "avatar": "avatar_url", "email": "email", "username": "username"}

So as you can see, only read/update/delete permissions are present here. I was not able to add write permission for any user, even though I have it checked in appwrite console for users' collection.

This is my react code for creating new users:

TypeScript
const newUser = await databases.createDocument(
            databaseId,
            usersCollectionId,
            ID.unique(),
            {
                accountId: newAccount.$id,
                email,
                username,
                avatar: avatarUrl,
            },
            [
                Permission.read(Role.user(newAccount.$id)),
                Permission.update(Role.user(newAccount.$id)),
                Permission.delete(Role.user(newAccount.$id)),
                Permission.write(Role.user(newAccount.$id)),
            ]

        )

Previously, I have not added permissions as a paramter in createDocument. The result was the same - it creates new user without write permission. I'm also adding screenshot from appwrite console to show my permissions' settings for users' collection.

TL;DR
Developers are encountering an issue with write permissions for all users when creating new documents. Despite setting write permissions in the code and in the Appwrite console, the error message "The current user is not authorized to perform the requested action" persists. The issue lies in the way permissions are being set for users in the code. The solution involves ensuring that the correct permissions are defined for each user in the `createDocument` method.
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