Back

[SOLVED] How does a user fetch their teams?

  • 0
  • Teams
  • Flutter
  • Users
  • Accounts
Farg0
31 Aug, 2023, 10:21

I read https://appwrite.io/docs/client/teams but I don't understand how it works? If I add a user to a team, then in the client application I can't track which team he belongs to in order to allow or deny him any actions depending on this. When creating a client session, Response does not have something like "memberships". The only way to determine which teams the user belongs to is /v1/users/{userId}/memberships through Server integration. Maybe I misunderstood the purpose of "teams"?

TL;DR
The user is asking how to fetch their teams in the client application. They are confused because the session object does not provide information about the teams the user belongs to. The solution is to use the Teams service and call `Teams(client).list();` to get a list of teams in which the current user is a member. This will allow the user to track which team they belong to and perform actions accordingly.
darShan
31 Aug, 2023, 10:45

From the docs: The Teams service allows you to group users of your project.

Simple example: Say you have an accounts team consisting of 5 members which should only have access to invoices databases, collections & its documents. Now a normal user would not & should not have access to this data (unless specified otherwise), but your accounts team will have. It is better to create teams/groups & grant them permissions rather than assigning permissions individually.

Teams(client).list(); would return a list of teams in which the current user is a member.

Farg0
31 Aug, 2023, 11:32

when creating a session, I can't see which team the user belongs to in order to give access to a particular function (when creating a session, I can't see which team the user belongs to)

darShan
31 Aug, 2023, 11:40

depending on your use-case, this would require the user to be logged in.

Farg0
31 Aug, 2023, 11:45

That's what I'm asking about. Why don't we have information about which teams a user belongs to after logging in? Session Object does not have this information.

So we can get the list of teams in /v1/teams, and then go through all the teams and /v1/teams/{teamId}/memberships and look for this user there. But what kind of solution is this?

Farg0
31 Aug, 2023, 11:48

This question has arisen because I want to display additional features for some groups, but checking which group the user belongs to is not implemented.

Farg0
31 Aug, 2023, 11:52

Session Object does not have information about the teams, having the user id I cannot see which teams it belongs to. Only iterate over all teams and then iterate over all users in the team.

Slava
31 Aug, 2023, 11:54

However, you can initiate a request to obtain the memberships of the currently logged-in user. https://appwrite.io/docs/client/teams?sdk=web-default#teamsList

Farg0
31 Aug, 2023, 12:01

Thanks, this is what I was looking for. I thought that List Teams returns a general list of teams and didn't pay attention to it.πŸ‘

Drake
31 Aug, 2023, 19:53

Can this thread be closed now?

Farg0
31 Aug, 2023, 20:28

Yes

Drake
31 Aug, 2023, 20:44

[SOLVED] How does a user fetch their teams?

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