It depends on you and what you want your app to do. If you only need to filter so that the user sees only the ones they have access to, permissions is enough. If you need any other filtering you'll need to model your data so that it can be filtered for that
Summary
The user was confused about how permissions work in Appwrite. They thought they would need to create a 'created_by' attribute to track the user who created a document, but Appwrite automatically handles this. By default, if permissions are not specified when creating a document, the current user is given read, update, and delete access. Appwrite knows the user's identity because they are authenticated and have a session. To ensure that a user only sees the documents they created, the user should only be granted create permission at the collection level. The update and delete permissions should be applied at the document level for that specific user. Other users should
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:18
But I tried using this method, I logged in as a separate user and when I tried retrieving the documents in the boards collection, I got all the documents even the ones not created by the current user.
Drake
Admin
Jun 4, 2023, 21:20
What are the permissions on your collection?
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:32
Users.
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:33
Meaning the users can create, read, update and delete documents.
Drake
Admin
Jun 4, 2023, 21:38
Do you see why that's the problem?
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:38
The reason I'm getting confused is because I had checked the code of other people and they took different approaches when fetching or adding documents to collections.
Seems it's because most of them are outdated but now I don't know how to make this possible
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:38
Oh? I don't. Please explain.
Drake
Admin
Jun 4, 2023, 21:39
You granted access to all documents to all users...that's why when a user logs in...they see all documents
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:42
I see. And how could I fix this?
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:42
Sorry I have to ask, this is my first time working with a backend service.
Drake
Admin
Jun 4, 2023, 21:45
Take a guess
KehindeJ
Rank 2: Process
Jun 4, 2023, 21:52
Would I only allow users to create, update, and delete documents?
Drake
Admin
Jun 4, 2023, 23:48
Do you really want any user to update/delete any document (including another user's)?
KehindeJ
Rank 2: Process
Jun 5, 2023, 10:27
No I don't.
KehindeJ
Rank 2: Process
Jun 5, 2023, 10:29
So I'm guessing I'm going to disable the permission for all users. But how would appwrite know which user created a document so that when a user logs in into his account, he sees only the document he has created?
Drake
Admin
Jun 5, 2023, 12:46
Don't disable create or else no one would be able to create a document.
Appwrite knows who the user is because they're authenticated and have a session
KehindeJ
Rank 2: Process
Jun 5, 2023, 13:10
I'm so confused here. But the user would also have to be able to update, retrieve and delete a document won't they? How should I set the permissions then?
Drake
Admin
Jun 5, 2023, 14:53
The update permission would be applied at the document level and only for that user versus granting access for all users
KehindeJ
Rank 2: Process
Jun 5, 2023, 15:03
Okay, so if I get you now, I'll only enable the create permission in the collection level?
KehindeJ
Rank 2: Process
Jun 5, 2023, 15:42
And then when retrieving the documents for a user, I won't need to pass in a query because appwrite would automatically detect the documents that the user created? Well of that's the way it works then that is amazing!
Drake
Admin
Jun 5, 2023, 15:43
it will automatically return only the documents the user has read access to. and, by default, if you don't pass permissions for a document when creating it, the current user is given read, update, and delete access to the document.
KehindeJ
Rank 2: Process
Jun 5, 2023, 15:45
Thank you so much, this was all that troubled me. I thought I'd have to create a created_by attribute to keep track of the user that created a document, I see I don't have to do that now. Thank you so much.
KehindeJ
Rank 2: Process
Jun 5, 2023, 15:46
So when I send a listDocuments method appwrite only returns the document that the user created. Nice!