Back

issue with functions getting user membership

  • 0
  • Users
sean_hanck
15 Feb, 2023, 03:07

Hello,

I have a function that is being triggered on document creation, the goal of which is to update the underlying permissions of the document. I am able to get the user id of the document creator from the event payload, but when I try to read the user's membership data as follows:

let userMemberships = await users.listMemberships( userId );

The api key that the function is using has the required user.read access assigned to it (it has ALL the access). I've tried userId formatted as "63e281f5412926a9296b" as well as "user:63e281f5412926a9296b" When wrapping it all in a loop, I get an empty array as the error when the code goes to the catch, when not wrapping in a loop I get the attached in the Error tab of the execution. In the Raw data pop out I see more info (attached as well), but it seems the User (role: guests) missing scope (functions.read) is the core issue (no clue it could be a rat hole).

I'm not sure where I would set that, if that is even the issue. From my sleuthing, it seems that similar messages occur when the user is anonymous. But there is no user and the api key has full perms. I've tried it with setSelfSigned set to true when initializing the client (and without it, its not in the sample code in the documentation).

Thanks for any help.

TL;DR
Issue: The user is experiencing an error when trying to retrieve membership data using a function triggered on document creation. The error message is "Error: getaddrinfo EAI_AGAIN hostname." The user is confused about the correct format for the userId and suspects that the missing user scope (functions.read) could be the issue. Solution: The user needs to make sure that `client.setEndpoint()` is called with the correct Appwrite endpoint. Additionally, they should ensure that the userId is formatted correctly.
Drake
15 Feb, 2023, 04:06

The raw data pop out is actually bugged so I wouldn't look at that. It'd actually be helpful if you create an issue for the pop out.

Error: getaddrinfo EAI_AGAIN hostname

As for the error, you're getting that because client.setEndpoint() is not being called with your Appwrite endpoint.

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