From 48bc3bbbe5734e35dc03249ddacec62cf66dcd3a Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Sun, 9 Nov 2025 23:30:59 -0800 Subject: [PATCH] use slug --- .../organization/routes/crud-members.test.ts | 4 +-- .../organization/routes/crud-members.ts | 25 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/better-auth/src/plugins/organization/routes/crud-members.test.ts b/packages/better-auth/src/plugins/organization/routes/crud-members.test.ts index 441b48d1ab..bc18f01c3c 100644 --- a/packages/better-auth/src/plugins/organization/routes/crud-members.test.ts +++ b/packages/better-auth/src/plugins/organization/routes/crud-members.test.ts @@ -82,8 +82,8 @@ describe("listMembers", async () => { organizationSlug: "test-second", }, }); - expect(members.data?.members.length).toBe(11); - expect(members.data?.total).toBe(11); + expect(members.data?.members.length).toBe(1); + expect(members.data?.total).toBe(1); }); it("should limit the number of members", async () => { diff --git a/packages/better-auth/src/plugins/organization/routes/crud-members.ts b/packages/better-auth/src/plugins/organization/routes/crud-members.ts index 9053d9208d..5c2b93170a 100644 --- a/packages/better-auth/src/plugins/organization/routes/crud-members.ts +++ b/packages/better-auth/src/plugins/organization/routes/crud-members.ts @@ -884,22 +884,21 @@ export const listMembers = (options: O) => let organizationId = ctx.query?.organizationId || session.session.activeOrganizationId; const adapter = getOrgAdapter(ctx.context, options); - if (!organizationId) { - if (ctx.query?.organizationSlug) { - const organization = await adapter.findOrganizationBySlug( - ctx.query?.organizationSlug, - ); - if (!organization) { - throw new APIError("BAD_REQUEST", { - message: ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND, - }); - } - organizationId = organization.id; - } else { + if (ctx.query?.organizationSlug) { + const organization = await adapter.findOrganizationBySlug( + ctx.query?.organizationSlug, + ); + if (!organization) { throw new APIError("BAD_REQUEST", { - message: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION, + message: ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND, }); } + organizationId = organization.id; + } + if (!organizationId) { + throw new APIError("BAD_REQUEST", { + message: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION, + }); } const isMember = await adapter.findMemberByOrgId({