Listing groups of a user

Hello,

I was trying to get the user groups. Even though user joined 2 different groups the code in the documentation i put below returns only one of them.

Can anyone tell me what the problem might be ?

Thanks…

The code:

string userId =session.UserId;

    var result = await client.ListUserGroupsAsync(session, userId);

    foreach (var ug in result.UserGroups)

    {

        var g = ug.Group;

        Debug.LogFormat("Group '{0}' role '{1}'", g.Id, ug.State);

    }

@hasosyn could you share the code where you add the user to the groups?

Could you also confirm via the Nakama Console that the user is actually in both groups?

Also, welcome to Nakama!

1 Like

Hello again @lugehorsam,
// group already open so user should have been in the group
const string groupId = “67616c96-9ee0-45b9-9fae-348dc974e133”;// example
await client.JoinGroupAsync(session, groupId);

// this is how i am trying to get the data(it returns only one group which user is superadmin)
string userId =session.UserId;
var result = await client.ListUserGroupsAsync(session, userId);
foreach (var ug in result.UserGroups)
{
var g = ug.Group;
Debug.LogFormat(“Group ‘{0}’ role ‘{1}’”, g.Id, ug.State);
}

1 Like

@hasosyn You’re only making one join group call.

1 Like

Hi again, @lugehorsam
I see what you mean
thank you for your help :slight_smile:

1 Like