Handle Unassigned Members Without User Association #758

Closed
opened 2026-03-13 08:03:10 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @yassinrais on GitHub (Mar 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When a member exists without an associated user, the current implementation fails due to an invalid query. Sometimes, we don’t want to remove a member but simply unassign the user. This case should be handled properly instead of causing failures.

  1. Unassign a user from a member without deleting the member record.
  2. Run the authentication flow that fetches member records.
  3. The query includes null in the in clause and fails.

Current vs. Expected behavior

prisma:error 
Invalid `db[getModelName(model)].findMany()` invocation in
/Users/xxxx/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:180:52

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, String, String, String).

 const result = await db[getModelName(model)].findMany({
        where: {
          id: {
            in: [
              null, <-- unassigned user id
              "ca7ffeb2-6582-4268-9975-1f920ca63bf5"
            ]
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          }
        },
        take: 100,
        skip: 0
      })

Expected Behavior:

  • Members without users should not break the query.
  • The system should gracefully handle unassigned members.

Suggested Fix:

  • Ensure the query handles null values correctly.
  • Allow members to exist without requiring a user association.

What version of Better Auth are you using?

^1.2.0

Provide environment information

N/A

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

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @yassinrais on GitHub (Mar 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When a member exists without an associated user, the current implementation fails due to an invalid query. Sometimes, we don’t want to remove a member but simply unassign the user. This case should be handled properly instead of causing failures. 1. Unassign a user from a member without deleting the member record. 2. Run the authentication flow that fetches member records. 3. The query includes `null` in the `in` clause and fails. ### Current vs. Expected behavior ``` prisma:error Invalid `db[getModelName(model)].findMany()` invocation in /Users/xxxx/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:180:52 Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, String, String, String). const result = await db[getModelName(model)].findMany({ where: { id: { in: [ null, <-- unassigned user id "ca7ffeb2-6582-4268-9975-1f920ca63bf5" ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } }, take: 100, skip: 0 }) ``` ### Expected Behavior: - Members without users should not break the query. - The system should gracefully handle unassigned members. ### Suggested Fix: - Ensure the query handles `null` values correctly. - Allow members to exist without requiring a user association. ### What version of Better Auth are you using? ^1.2.0 ### Provide environment information ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:03:10 -05:00
Author
Owner

@Kinfe123 commented on GitHub (May 30, 2025):

Currently we are using userId as reference of marking the relationship between and members and their respective orgs but you can look at an org invitation and how provisioning works on org plugins but will address the edge case here

@Kinfe123 commented on GitHub (May 30, 2025): Currently we are using userId as reference of marking the relationship between and members and their respective orgs but you can look at an org invitation and how provisioning works on org plugins but will address the edge case here
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#758