Back

Listing User-Specific Documents from a Collection?

  • 0
  • Databases
  • Cloud
Ranga Reddy
14 Jun, 2023, 03:59

I have a collection that has write-only permission for all users, and the remaining permissions are based on the user ID. The Apple SDK is working fine as expected, meaning a user can only see their own entries.

However, I'm facing an issue with my Python cloud function, which needs to read data specific to a particular user ID. I want to list documents that are specific to the requested user instead of displaying the entire collection.

Quick help appreciated, Between this is crucial for the hackathon!

TL;DR
The user is experiencing an issue with their Python cloud function where they need to list documents that are specific to a requested user ID. They have a collection with write-only permission for all users, and the remaining permissions are based on the user ID. They are seeking quick help for this issue, as it is crucial for a hackathon. Solution: The user can initialize their function client using the user JWT, which will ensure that only documents available for the user will be returned. They can refer to the provided links for more information on function variables and executing functions with the user JWT.
Binyamin
14 Jun, 2023, 04:17

When executing a function, if it is done by the user then the current user JWT is being sent.

That means you can initialize your function client using the user JWT.

Making use of the user JWT will make sure only documents that available for the user will return. Just like you're using the swift SDK.

Binyamin
14 Jun, 2023, 04:17

First you can find out about function variables here https://appwrite.io/docs/functions#functionVariables

Binyamin
14 Jun, 2023, 04:19
Ranga Reddy
14 Jun, 2023, 13:08

Thanks @Binyamin, I can almost see it but I have userId mismatch.

{"executedBy":"64630bd18715e9d8b0a9","jwt":"xxxxxxxxxxxxxxxx","message":"Successfully Generated","sessionId":"6489b3a7ba985cb71e11","timestamp":"2023-06-14 12:57:28","userId":"64892bc8d83bfea54d34"}

userId is passing from local - exists in project executedBy function variable user id - does not exists in project

Binyamin
14 Jun, 2023, 13:24

What is this object?

Binyamin
14 Jun, 2023, 13:24

How have you initialized the client?

Ranga Reddy
14 Jun, 2023, 15:46
TypeScript
class NetworkManager {
    static let shared = NetworkManager()
    let client: Client
    let account: Account
    let databases: Databases
    let functions: Functions
    let storage: Storage

    private init() {
        self.client = Client()
            .setEndpoint(K.END_POINT)
            .setProject(K.PROJECT_ID)
            .setSelfSigned()
        self.account = Account(client)
        self.databases = Databases(client)
        self.functions = Functions(client)
        self.storage = Storage(client)

        Task { try! await listSessions() }    }
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