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

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

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.

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

` 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
)`

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

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.

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

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

err nevermind

I see ones read and ones write sorry

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

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?

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

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.

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

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

you will need a function for that instead

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

But not for other user, only for user that is logged in. Then you can set permissions for anyone
Recommended threads
- CSV Not Importing
We don’t seem to having any luck importing a simple .csv file. The import function acts like it’s working but no data imports or is shown in the collection The...
- Appwrite Cloud Custom Domains Issue
I’m trying to configure my custom domain api.kondri.lt (CNAME pointing to appwrite.network., also tried fra.cloud.appwrite.io with no luck ) but encountering a ...
- Persistent 401 Unauthorized on all authe...
Hello, I'm facing a critical 401 Unauthorized error on my admin panel app and have exhausted all debugging options. The Problem: When my React app on localhos...
