Skip to content

Admin Clients member count includes the hidden provisioning service account #262

@ChesterSchendel

Description

@ChesterSchendel

Problem

On /admin/clients, the TEAM CLIENTS member count is inflated by 1 — it counts the hidden provisioning service account. A team with one Team Lead and no designers shows "2 members" instead of 1. Found 2026-05-29 testing "Prod Test Co".

Root cause

src/app/api/admin/clients/route.ts line 62:

membersCount: org.membersCount ?? 0,

This is Clerk's raw membersCount (from includeMembersCount: true). Every provisioned org has the service account as a member (it's createdBy / owner), so the count is always +1. The roster list correctly filters the service account via isProvisioningUser, but the count here doesn't.

Proposed fix

Subtract the service account when the org was provisioned by it:

const provisioner = provisioningUserId();
const raw = org.membersCount ?? 0;
const membersCount =
  provisioner && org.createdBy === provisioner ? Math.max(0, raw - 1) : raw;

Using the createdBy === provisioner guard (rather than a blanket -1) keeps legacy/non-provisioned orgs accurate. Cheap — no extra Clerk calls.

Priority

Before the client demo — an inflated member count is confusing in the provisioning view Ward will demo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions