[GH-ISSUE #6065] Get Full Organization Return 500 despite members and organizations being present #27736

Closed
opened 2026-04-17 18:54:46 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @wrmichaelmak on GitHub (Nov 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6065

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Call /api/auth/organization/get-full-organization endpoint via UI

Current vs. Expected behavior

We are getting this error:

2025-11-18T11:45:39.342Z ERROR [Better Auth]: BetterAuthError [Error [BetterAuthError]: Unexpected error: User not found for member] {
  cause: undefined
}
# SERVER_ERROR:  [Error [BetterAuthError]: Unexpected error: User not found for member] {
  cause: undefined
}
 GET /api/auth/organization/get-full-organization 500 in 436ms

Despite in our mongodb that we can see the user is a member of an organization.

Would expect a 200

What version of Better Auth are you using?

1.3.13

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000",
    "release": "25.0.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.19 GB"
  },
  "node": {
    "version": "v22.20.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "15.5.2"
    },
    {
      "name": "react",
      "version": "19.1.0"
    }
  ],
  "databases": [
    {
      "name": "mongodb",
      "version": "^6.19.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.13",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

It seems like there is an issue with the mapping? New users are working fine and I manually change the organization ID in the members table, and it is fine as well

No response

Originally created by @wrmichaelmak on GitHub (Nov 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6065 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Call `/api/auth/organization/get-full-organization` endpoint via UI ### Current vs. Expected behavior We are getting this error: ``` 2025-11-18T11:45:39.342Z ERROR [Better Auth]: BetterAuthError [Error [BetterAuthError]: Unexpected error: User not found for member] { cause: undefined } # SERVER_ERROR: [Error [BetterAuthError]: Unexpected error: User not found for member] { cause: undefined } GET /api/auth/organization/get-full-organization 500 in 436ms ``` Despite in our mongodb that we can see the user is a member of an organization. Would expect a 200 ### What version of Better Auth are you using? 1.3.13 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000", "release": "25.0.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.19 GB" }, "node": { "version": "v22.20.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": [ { "name": "next", "version": "15.5.2" }, { "name": "react", "version": "19.1.0" } ], "databases": [ { "name": "mongodb", "version": "^6.19.0" } ], "betterAuth": { "version": "^1.3.13", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context It seems like there is an issue with the mapping? New users are working fine and I manually change the organization ID in the members table, and it is fine as well _No response_
GiteaMirror added the lockedbug labels 2026-04-17 18:54:46 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 18, 2025):

Hi there, thanks for reporting the issue. The error “User not found for member” suggests that while the membership record exists in your database, the corresponding user record isn’t being found during the full organization retrieval process. Here are a few troubleshooting steps:

• Verify that every membership record’s user ID correctly maps to an existing user in your MongoDB. It might help to run a quick integrity check on your users and memberships collections to ensure there are no mismatches. [1]

• Double-check that any recent database migrations or schema changes didn’t inadvertently break the relationship between users and organization members. In some cases, changes to organization or user schemas (for instance, when reserved names are involved) can cause lookup failures. [2]

• Review your logs around the time the error occurs to see if any other related warnings appear. Adding extra logging in the getFullOrganization endpoint to trace the member-to-user lookup may reveal more details about what’s failing. [3]

Does your setup include any custom modifications on how membership relations are stored? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3547470828 --> @better-auth-agent[bot] commented on GitHub (Nov 18, 2025): Hi there, thanks for reporting the issue. The error “User not found for member” suggests that while the membership record exists in your database, the corresponding user record isn’t being found during the full organization retrieval process. Here are a few troubleshooting steps: • Verify that every membership record’s user ID correctly maps to an existing user in your MongoDB. It might help to run a quick integrity check on your users and memberships collections to ensure there are no mismatches. [[1]](https://github.com/better-auth/better-auth/issues/4125) • Double-check that any recent database migrations or schema changes didn’t inadvertently break the relationship between users and organization members. In some cases, changes to organization or user schemas (for instance, when reserved names are involved) can cause lookup failures. [[2]](https://github.com/better-auth/better-auth/issues/1852) • Review your logs around the time the error occurs to see if any other related warnings appear. Adding extra logging in the getFullOrganization endpoint to trace the member-to-user lookup may reveal more details about what’s failing. [[3]](https://github.com/better-auth/better-auth/issues/4386) Does your setup include any custom modifications on how membership relations are stored? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@rovertrack commented on GitHub (Nov 18, 2025):

according to above , reply did that solved you issue?

<!-- gh-comment-id:3547852669 --> @rovertrack commented on GitHub (Nov 18, 2025): according to above , reply did that solved you issue?
Author
Owner

@wrmichaelmak commented on GitHub (Nov 18, 2025):

No it did not, I checked the database and can see the organization. We did authclient.useListOrganization and we can actually see the organization in the response but we could not getFullOrganization :( New users are ok - we created a new user and it has no issue but for old users it is not working

<!-- gh-comment-id:3547862092 --> @wrmichaelmak commented on GitHub (Nov 18, 2025): No it did not, I checked the database and can see the organization. We did authclient.useListOrganization and we can actually see the organization in the response but we could not getFullOrganization :( New users are ok - we created a new user and it has no issue but for old users it is not working
Author
Owner

@wrmichaelmak commented on GitHub (Nov 18, 2025):

I did more checks and found out that there was a member entity which belongs to a deleted user (which was manually removed). Which caused the failure

<!-- gh-comment-id:3549316368 --> @wrmichaelmak commented on GitHub (Nov 18, 2025): I did more checks and found out that there was a member entity which belongs to a deleted user (which was manually removed). Which caused the failure
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27736