Client Side listMembers throw 404 #1624

Closed
opened 2026-03-13 08:52:07 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Kalyankr on GitHub (Aug 1, 2025).

I am trying to get the list of memebr of an organization on client side I get 404, but when i used the Server side api, I get the data.

`export default function MembersTable() {
const session = useSession();
console.log(session?.data?.session.activeOrganizationId);

const { data, isLoading, isError } = useQuery({
queryKey: ["members-list"],
queryFn: async () => {
const res = await authClient.organization.listMembers({
organizationId: session?.data?.session.activeOrganizationId,
limit: 100,
offset: 0,
sortBy: "createdAt",
sortDirection: "desc",
filterField: "createdAt",
filterOperator: "eq",
filterValue: "value",
});
return res;
},
});

// const data = await auth.api.listMembers({
// headers: await headers(),
// });

return

{JSON.stringify(data, null, 2)}
;
}`

I even tried passing the organization ID hard coded still got the same 404
using : "better-auth": "^1.3.4",

Any help is much appreciated. Thank you

Originally created by @Kalyankr on GitHub (Aug 1, 2025). I am trying to get the list of memebr of an organization on client side I get 404, but when i used the Server side api, I get the data. `export default function MembersTable() { const session = useSession(); console.log(session?.data?.session.activeOrganizationId); const { data, isLoading, isError } = useQuery({ queryKey: ["members-list"], queryFn: async () => { const res = await authClient.organization.listMembers({ organizationId: session?.data?.session.activeOrganizationId, limit: 100, offset: 0, sortBy: "createdAt", sortDirection: "desc", filterField: "createdAt", filterOperator: "eq", filterValue: "value", }); return res; }, }); // const data = await auth.api.listMembers({ // headers: await headers(), // }); return <div>{JSON.stringify(data, null, 2)}</div>; }` I even tried passing the organization ID hard coded still got the same 404 using : "better-auth": "^1.3.4", Any help is much appreciated. Thank you
GiteaMirror added the javascript label 2026-03-13 08:52:07 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 1, 2025):

This 404 on client-side listMembers is a known issue in better-auth v1.3.4, especially with the MongoDB adapter. The root causes are usually session context not being properly available to the organization endpoints on the client, plugin order/type inference issues, or inconsistent ID types in your DB. Server-side calls work because they have direct access to the session and DB context, but client-side calls depend on session propagation via cookies/headers, which can break in certain setups or if the session is missing activeOrganizationId example.

Here’s what you should check:

  • Make sure your session includes activeOrganizationId. If you’re using customSession or have plugins in a specific order, you may need a session.create.before hook to explicitly set this by querying the member table for the user’s org membership example.
  • Ensure your client and server both include the organization plugin, and that the client config enables teams if you use them example.
  • Use organizationId (UUID) in all membership checks and API calls; using slugs can cause errors in this version example.
  • If you’re on MongoDB, make sure userId and organizationId are stored and queried as either all strings or all ObjectIds—type mismatches here are a common cause of membership check failures example.
  • Client-side API calls must include proper session cookies/headers. If you’re running in a non-standard environment or using a custom fetch, double-check that credentials are sent.

If you want a quick workaround, you can fetch members server-side (where session context is always correct) and expose that via your own API route. For a permanent fix, upgrade to a version after 2025-07-26, which includes major fixes for session propagation, membership checks, and client/server schema inference example.

If you share your Better Auth config or session hook code, I can help spot any issues.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 1, 2025): <!-- Answer --> This 404 on client-side listMembers is a known issue in better-auth v1.3.4, especially with the MongoDB adapter. The root causes are usually session context not being properly available to the organization endpoints on the client, plugin order/type inference issues, or inconsistent ID types in your DB. Server-side calls work because they have direct access to the session and DB context, but client-side calls depend on session propagation via cookies/headers, which can break in certain setups or if the session is missing `activeOrganizationId` [example](https://github.com/better-auth/better-auth/issues/3012). Here’s what you should check: - Make sure your session includes `activeOrganizationId`. If you’re using customSession or have plugins in a specific order, you may need a `session.create.before` hook to explicitly set this by querying the member table for the user’s org membership [example](https://github.com/better-auth/better-auth/issues/3233). - Ensure your client and server both include the organization plugin, and that the client config enables teams if you use them [example](https://github.com/better-auth/better-auth/issues/3079). - Use organizationId (UUID) in all membership checks and API calls; using slugs can cause errors in this version [example](https://github.com/better-auth/better-auth/issues/3528). - If you’re on MongoDB, make sure userId and organizationId are stored and queried as either all strings or all ObjectIds—type mismatches here are a common cause of membership check failures [example](https://github.com/better-auth/better-auth/issues/3695). - Client-side API calls must include proper session cookies/headers. If you’re running in a non-standard environment or using a custom fetch, double-check that credentials are sent. If you want a quick workaround, you can fetch members server-side (where session context is always correct) and expose that via your own API route. For a permanent fix, upgrade to a version after 2025-07-26, which includes major fixes for session propagation, membership checks, and client/server schema inference [example](https://github.com/better-auth/better-auth/pull/3624). If you share your Better Auth config or session hook code, I can help spot any issues. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/eb1b4c4c-a36b-478e-8d0f-1048d90771d1?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3745)
Author
Owner

@Kinfe123 commented on GitHub (Aug 7, 2025):

have you please checked your authclient baseURL or can you please share your setup ?

@Kinfe123 commented on GitHub (Aug 7, 2025): have you please checked your authclient baseURL or can you please share your setup ?
Author
Owner

@Kinfe123 commented on GitHub (Aug 9, 2025):

Closing this as there was no response and seems to be more of user side issue.

@Kinfe123 commented on GitHub (Aug 9, 2025): Closing this as there was no response and seems to be more of user side issue.
Author
Owner

@yumartins commented on GitHub (Aug 10, 2025):

Same issue here, and I think that everything is okay with the session, because the only issue that I have is about this specific endpoint (I'm sending a screenshot to show my auth session)

Image
@yumartins commented on GitHub (Aug 10, 2025): Same issue here, and I think that everything is okay with the session, because the only issue that I have is about this specific endpoint (I'm sending a screenshot to show my auth session) <img width="1371" height="696" alt="Image" src="https://github.com/user-attachments/assets/3920fb38-a4a0-4c0b-9f60-2406a369d03f" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1624