[GH-ISSUE #3414] organizationId not accepted in getActiveMember query #26919

Closed
opened 2026-04-17 17:40:07 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @brunowego on GitHub (Jul 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3414

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up Better Auth on the backend
  2. Try calling organization.getActiveMember() on the client with a query parameter:
organization.getActiveMember({
  query: {
    organizationId: workspaceId,
  },
})
  1. The organizationId is ignored or has no effect

Current vs. Expected behavior

Expected:

Passing the organizationId in the query object should return the active member for that specific organization.

Current:

The result either ignores the organizationId or does not reflect the intended context. I suspect the organization context is expected to come from a cookie or session, but this is unclear in the docs.

What version of Better Auth are you using?

1.2.12

Provide environment information

- OS: macOS 14.5
- Browser: Chrome 126.0

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

Client

Auth config (if applicable)

import { drizzleAdapter } from 'better-auth/adapters/drizzle'
import { admin, organization } from 'better-auth/plugins'
import { v4 as uuidv4 } from 'uuid'
import { type BetterAuthOptions, betterAuth } from 'better-auth'
import { cache } from 'react'
import { headers } from 'next/headers'

import db from '@acme/db'

import senv from './lib/env/server'
import { ac, roles } from './permissions'

export const config = {
  database: drizzleAdapter(db, {
    provider: 'pg',
    usePlural: true,
  }),
  socialProviders: {
    ...(senv.GOOGLE_CLIENT_ID && senv.GOOGLE_CLIENT_SECRET
      ? {
          google: {
            clientId: senv.GOOGLE_CLIENT_ID,
            clientSecret: senv.GOOGLE_CLIENT_SECRET,
            mapProfileToUser: (profile) => {
              return {
                ...profile,
                firstName: profile.given_name,
                lastName: profile.family_name,
                image: profile.picture?.replace('=s96-c', '=s256-c'),
              }
            },
          },
        }
      : {}),
  },
  plugins: [
    admin({
      defaultRole: 'user',
      adminRoles: ['admin'],
    }),
    organization({
      ac,
      roles,
      member: {
        additionalFields: {
          jobTitle: {
            type: 'string',
            required: false,
            fieldName: 'jobTitle',
          },
          department: {
            type: 'string',
            required: false,
            fieldName: 'department',
          },
          location: {
            type: 'string',
            required: false,
            fieldName: 'location',
          },
        },
      },
    }),
  ],
  user: {
    additionalFields: {
      firstName: {
        type: 'string',
        fieldName: 'firstName',
      },
      lastName: {
        type: 'string',
        required: false,
        fieldName: 'lastName',
      },
      theme: {
        type: 'string',
        required: false,
        fieldName: 'theme',
      },
    },
  },
  session: {
    expiresIn: 60 * 60 * 24 * 7, // 7 days
    updateAge: 60 * 60 * 24, // 1 day
  },
  advanced: {
    cookiePrefix: 'acme',
    database: {
      generateId: () => uuidv4(),
    },
  },
  databaseHooks: {
    user: {
      create: {
        before: async (user) => {
          if (user.email.endsWith('@acme.com')) {
            return {
              data: {
                ...user,
                role: 'admin',
              },
            }
          }

          return {
            data: {
              ...user,
            },
          }
        },
      },
    },
  },
} satisfies BetterAuthOptions

const auth = betterAuth(config)

const getCurrentSession = cache(
  async () => await auth.api.getSession({ headers: await headers() }),
)

export { auth as default, getCurrentSession }

Additional context

• I’m using React Query on the client to fetch the member data.
• The call works, but always returns the member for the session’s organization, ignoring the one I pass via query.
• This behavior is unclear in the documentation — is it expected that getActiveMember() always uses the current session context?
• If organizationId should not be passed manually, is there an alternative method to get the member of a specific organization from the client?

Originally created by @brunowego on GitHub (Jul 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3414 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Set up Better Auth on the backend 2. Try calling organization.getActiveMember() on the client with a query parameter: ```ts organization.getActiveMember({ query: { organizationId: workspaceId, }, }) ``` 3. The organizationId is ignored or has no effect ### Current vs. Expected behavior Expected: Passing the organizationId in the query object should return the active member for that specific organization. Current: The result either ignores the organizationId or does not reflect the intended context. I suspect the organization context is expected to come from a cookie or session, but this is unclear in the docs. ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash - OS: macOS 14.5 - Browser: Chrome 126.0 ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { drizzleAdapter } from 'better-auth/adapters/drizzle' import { admin, organization } from 'better-auth/plugins' import { v4 as uuidv4 } from 'uuid' import { type BetterAuthOptions, betterAuth } from 'better-auth' import { cache } from 'react' import { headers } from 'next/headers' import db from '@acme/db' import senv from './lib/env/server' import { ac, roles } from './permissions' export const config = { database: drizzleAdapter(db, { provider: 'pg', usePlural: true, }), socialProviders: { ...(senv.GOOGLE_CLIENT_ID && senv.GOOGLE_CLIENT_SECRET ? { google: { clientId: senv.GOOGLE_CLIENT_ID, clientSecret: senv.GOOGLE_CLIENT_SECRET, mapProfileToUser: (profile) => { return { ...profile, firstName: profile.given_name, lastName: profile.family_name, image: profile.picture?.replace('=s96-c', '=s256-c'), } }, }, } : {}), }, plugins: [ admin({ defaultRole: 'user', adminRoles: ['admin'], }), organization({ ac, roles, member: { additionalFields: { jobTitle: { type: 'string', required: false, fieldName: 'jobTitle', }, department: { type: 'string', required: false, fieldName: 'department', }, location: { type: 'string', required: false, fieldName: 'location', }, }, }, }), ], user: { additionalFields: { firstName: { type: 'string', fieldName: 'firstName', }, lastName: { type: 'string', required: false, fieldName: 'lastName', }, theme: { type: 'string', required: false, fieldName: 'theme', }, }, }, session: { expiresIn: 60 * 60 * 24 * 7, // 7 days updateAge: 60 * 60 * 24, // 1 day }, advanced: { cookiePrefix: 'acme', database: { generateId: () => uuidv4(), }, }, databaseHooks: { user: { create: { before: async (user) => { if (user.email.endsWith('@acme.com')) { return { data: { ...user, role: 'admin', }, } } return { data: { ...user, }, } }, }, }, }, } satisfies BetterAuthOptions const auth = betterAuth(config) const getCurrentSession = cache( async () => await auth.api.getSession({ headers: await headers() }), ) export { auth as default, getCurrentSession } ``` ### Additional context • I’m using React Query on the client to fetch the member data. • The call works, but always returns the member for the session’s organization, ignoring the one I pass via query. • This behavior is unclear in the documentation — is it expected that getActiveMember() always uses the current session context? • If organizationId should not be passed manually, is there an alternative method to get the member of a specific organization from the client?
GiteaMirror added the locked label 2026-04-17 17:40:07 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 16, 2025):

Hi @brunowego! I'm Dosu and I’m helping the better-auth team.

You're correct—passing organizationId in the query to organization.getActiveMember() is ignored. The organization context for getActiveMember() is determined by the current session or cookies, not by a manually-passed organizationId. This isn't clearly documented, but it's the intended behavior in v1.2.12. If you need to fetch the member for a specific organization, you'll need to use a different method or adjust your approach, as getActiveMember() is designed to always use the session's organization context and does not support overriding it via query parameter. More details on session and organization context can be found in related discussions about plugin order and session management [source].

To reply, just mention @dosu.


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

<!-- gh-comment-id:3080017084 --> @dosubot[bot] commented on GitHub (Jul 16, 2025): <!-- Greeting --> Hi @brunowego! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're correct—passing organizationId in the query to organization.getActiveMember() is ignored. The organization context for getActiveMember() is determined by the current session or cookies, not by a manually-passed organizationId. This isn't clearly documented, but it's the intended behavior in v1.2.12. If you need to fetch the member for a specific organization, you'll need to use a different method or adjust your approach, as getActiveMember() is designed to always use the session's organization context and does not support overriding it via query parameter. More details on session and organization context can be found in related discussions about plugin order and session management [[source]](https://github.com/better-auth/better-auth/issues/3233). <!-- 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/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/341d3574-e0a9-47f3-a55a-356d9b06eef5?feedback_type=other)</sup>&nbsp;&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/3414)
Author
Owner

@Kinfe123 commented on GitHub (Jul 16, 2025):

you can use getFullOrganization() by passing org slug or org id as query params to get the details about the org including the member , invitation and teams if enabled

<!-- gh-comment-id:3080623271 --> @Kinfe123 commented on GitHub (Jul 16, 2025): you can use getFullOrganization() by passing org slug or org id as query params to get the details about the org including the member , invitation and teams if enabled
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26919