Back

User permission

  • 0
  • Databases
  • Web
parlament
5 Oct, 2023, 21:06

How to add read permission for another user? I have tried to create read permission for me and another user and got an error

TL;DR
The user is asking about setting permissions for specific users in an application using the Appwrite platform. They are confused about whether it is possible to set permissions for other users or only for the logged-in user. They mention looking at the documentation and finding an example of setting permissions on the client side, but they are not sure if it is the correct approach. They also mention encountering an error when trying to create a document without specifying permissions and ask if they need to set permissions for the creator of the message. They get clarification on this and realize that the creator automatically gets document permissions. They also mention encountering an error when trying to set permissions for
Kenny
5 Oct, 2023, 21:21

Can you provide a snippet of the code you're using to set the permissions?

otik
6 Oct, 2023, 11:28

You cant do that. You cant set permissions to other users through web sdk, only for your self. Only way to add permissions to other user is to use API-key, It means use appwrite functions or your own backend.

parlament
6 Oct, 2023, 12:10

And what is the point to set permissions only to your self? There is no 'read' permission for all users on my collection and i want to give some of them permission to fetch this document

parlament
6 Oct, 2023, 12:11

` const permissions = [Permission.write(Role.user(user.$id))]

TypeScript
if (chat.type === ChatType.Global)
  permissions.push(Permission.read(Role.users()))
if (chat.type === ChatType.Private && friendId) {
  permissions.push(Permission.read(Role.user(user.$id)))
  permissions.push(Permission.read(Role.user(friendId)))
}

await databases.createDocument<MessageExternal>(
  DATABASE_ID,
  COLLECTION_ID_MESSAGES,
  ID.unique(),
  messageSent,
  permissions
)`
Kenny
6 Oct, 2023, 13:18

I think for that first if statement you'd want Role.Any(). Not sure if that would be causing the issue though

Kenny
6 Oct, 2023, 13:20

https://appwrite.io/docs/references/cloud/client-web/databases

The web documentation says that you can create a document with permissions and update a documents permissions, so I'm not sure if the person who said you can only do this with the server sdk is right.

parlament
6 Oct, 2023, 13:23

Everything is fine with first if, permissions in the second one causes an error

Kenny
6 Oct, 2023, 13:26

Do you need to push again the same permission you've already set outside of the if block?

Kenny
6 Oct, 2023, 13:26

err nevermind

Kenny
6 Oct, 2023, 13:26

I see ones read and ones write sorry

Kenny
6 Oct, 2023, 13:28

Are you getting that error when trying to set the permission or when trying to view that message?

Kenny
6 Oct, 2023, 13:29

Would you actually need to set the creator of the messages permissions, since the user signed in is who created the message I think they automatically get document permissions over that new item?

parlament
6 Oct, 2023, 14:36

databases.createDocument is failing with error i attached before. Yes, i need to specify permissions. They are not created automatically

Kenny
6 Oct, 2023, 14:39

If you create a resource using a Client SDK without explicit permissions, the creator will be granted read, update, and delete permissions on that resource by default.

https://appwrite.io/docs/advanced/platform/permissions

parlament
6 Oct, 2023, 14:54

This is not a problem, i can not give permission for another user

D5
6 Oct, 2023, 15:01

If I'm not wrong, you can't give permission for another user client sided

D5
6 Oct, 2023, 15:01

you will need a function for that instead

Kenny
6 Oct, 2023, 15:07

Really? I was looking at the documentation and they have an example setting permissions on client side.

https://appwrite.io/docs/advanced/platform/permissions#:~:text=Example%20%231%20%2D%20Basic%20usage

otik
7 Oct, 2023, 08:43

But not for other user, only for user that is logged in. Then you can set permissions for anyone

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