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
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...