Rank 1: Thread
How to add read permission for another user? I have tried to create read permission for me and another user and got an error
Votes
0
Replies
19
Participants
Unknown
Messages
20
Rank 1: Thread
How to add read permission for another user? I have tried to create read permission for me and another user and got an error
Moderator
Can you provide a snippet of the code you're using to set the permissions?
Rank 2: Process
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.
Rank 1: Thread
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
Rank 1: Thread
`
const permissions = [Permission.write(Role.user(user.$id))]
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
)`
Moderator
I think for that first if statement you'd want Role.Any(). Not sure if that would be causing the issue though
Moderator
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.
Rank 1: Thread
Everything is fine with first if, permissions in the second one causes an error
Moderator
Do you need to push again the same permission you've already set outside of the if block?
Moderator
err nevermind
Moderator
I see ones read and ones write sorry
Moderator
Are you getting that error when trying to set the permission or when trying to view that message?
Moderator
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?
Rank 1: Thread
databases.createDocument is failing with error i attached before. Yes, i need to specify permissions. They are not created automatically
Moderator
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.
Rank 1: Thread
This is not a problem, i can not give permission for another user
Moderator
If I'm not wrong, you can't give permission for another user client sided
Moderator
you will need a function for that instead
Moderator
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
Rank 2: Process
But not for other user, only for user that is logged in. Then you can set permissions for anyone