How to achieve typical organization users table view
Closed this issue · 2 comments
Hey all,
We are trying to create an organization users view in our application and there doesn't seem to be a straightforward way of doing so. (Image below) Right now to achieve this, I am combining the responses of listUsers()
and listOrganizationMembers()
.
I am basically getting all the users in my WorkOS tenant, regardless of organization_id. Then combining this with the response of listing organization memberships.
IIRC, when using listUsers()
and passing the organization_id
, this only returns the active/accepted users in the org. It doesn't contain pending/inactive users.
This method also has an issue where the max return from listUsers()
is 100, so if my WorkOS tenant has over 100 users, it becomes a bit messy. (Some users for the given org, will not be returned in the initial 100 results)
const { data: users } = await workosClient.userManagement.listUsers({
limit: 100,
});
const { data: organizationMembers } =
await workosClient.userManagement.listOrganizationMemberships({
organizationId,
statuses: ["active", "inactive", "pending"],
});
Basically what we are trying to achieve is something like WorkOS's org view. Pretty typical (Name, Email, Picture, Role, Status)
Is it safe to say there is no trivial way to accomplish this?
Hey there, you can still accomplish this by using auto-pagination in your listUsers
method call, which gets you all your users instead of just the first 100.
However I think the biggest issue here is that you might be using WorkOS as a database to render your organization view. If you're doing the above on a page load you'll start to get longer and longer wait times as your user base grows. We recommend you store this data on your end instead with a reference to the WorkOS user ID.
You could rely on webhooks to keep your database in sync with any user updates instead of having to poll the API every time you want to render this view.