[GH-ISSUE #7005] Unexplained getActiveOrganization() in docs #19330

Closed
opened 2026-04-15 18:16:26 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @thedevdavid on GitHub (Dec 26, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7005

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Organization plugin docs set active organization section recommends using database hooks for setting active org on session create. The code block recommends:

export const auth = betterAuth({
  databaseHooks: {
    session: {
      create: {
        before: async (session) => {
          const organization = await getActiveOrganization(session.userId);
          return {
            data: {
              ...session,
              activeOrganizationId: organization.id,
            },
          };
        },
      },
    },
  },
});

but getActiveOrganization() function doesn't appear anywhere in the documentation. Also, I'm not sure what is it even supposed to convey. How would I get the active org from session if the session is being created right now?

Current vs. Expected behavior

Documenting existing functionality only or noting if something needs implementation by the developer.

What version of Better Auth are you using?

1.4.9

System info

N/A

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

Documentation

Auth config (if applicable)

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

Additional context

No response

Originally created by @thedevdavid on GitHub (Dec 26, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7005 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Organization plugin docs [set active organization](https://www.better-auth.com/docs/plugins/organization#set-active-organization) section recommends using database hooks for setting active org on session create. The code block recommends: ``` export const auth = betterAuth({ databaseHooks: { session: { create: { before: async (session) => { const organization = await getActiveOrganization(session.userId); return { data: { ...session, activeOrganizationId: organization.id, }, }; }, }, }, }, }); ``` but `getActiveOrganization()` function doesn't appear anywhere in the documentation. Also, I'm not sure what is it even supposed to convey. How would I get the active org from session if the session is being created right now? ### Current vs. Expected behavior Documenting existing functionality only or noting if something needs implementation by the developer. ### What version of Better Auth are you using? 1.4.9 ### System info ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Documentation ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 18:16:26 -05:00
Author
Owner

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

It seems like you're looking for clarification on the getActiveOrganization() function mentioned in the Better Auth documentation. This function isn't explicitly documented, and its purpose might not be clear. However, the documentation mentions that you can manage the active organization in the client-side and that the active organization can be set using organization.setActive, which might be part of a broader approach in your authentication flow.

To get the active organization when creating a session, you would generally call a method designed to retrieve the active organization for a user. This could involve a server request to fetch the active organization based on the user's ID or any session-related identifiers you have.

If getActiveOrganization() is not defined in your current setup, you might consider using authClient.useActiveOrganization() hook instead, as it allows you to access the currently active organization directly.

Since the function isn't documented, it could be beneficial to reach out to members of the Better Auth team for more detailed insights. You can tag @bekacru or @ping__ for assistance.

Do you have any other questions about implementing Better Auth features or anything specific you're curious about?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3692871777 --> @better-auth-agent[bot] commented on GitHub (Dec 26, 2025): It seems like you're looking for clarification on the `getActiveOrganization()` function mentioned in the Better Auth documentation. This function isn't explicitly documented, and its purpose might not be clear. However, the documentation mentions that you can manage the active organization in the client-side and that the active organization can be set using `organization.setActive`, which might be part of a broader approach in your authentication flow. To get the active organization when creating a session, you would generally call a method designed to retrieve the active organization for a user. This could involve a server request to fetch the active organization based on the user's ID or any session-related identifiers you have. If `getActiveOrganization()` is not defined in your current setup, you might consider using `authClient.useActiveOrganization()` hook instead, as it allows you to access the currently active organization directly. Since the function isn't documented, it could be beneficial to reach out to members of the Better Auth team for more detailed insights. You can tag @bekacru or @ping__ for assistance. Do you have any other questions about implementing Better Auth features or anything specific you're curious about? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@bytaesu commented on GitHub (Dec 26, 2025):

Hi @thedevdavid,

When a new session is created, activeOrganizationId is not set on the session even if the user is a member of an organization. If you want it to be set at creation time, you'll need to handle it with custom logic (e.g. db query)

This behavior should be clearer. I'll fix it 🙂


https://github.com/user-attachments/assets/541a82e6-02cc-450c-a0a9-70f61a602678

<!-- gh-comment-id:3693422926 --> @bytaesu commented on GitHub (Dec 26, 2025): Hi @thedevdavid, When a new session is created, `activeOrganizationId` is not set on the session even if the user is a member of an organization. If you want it to be set at creation time, you'll need to handle it with custom logic (e.g. db query) This behavior should be clearer. I'll fix it 🙂 --- https://github.com/user-attachments/assets/541a82e6-02cc-450c-a0a9-70f61a602678
Author
Owner

@thedevdavid commented on GitHub (Dec 28, 2025):

Thanks, @bytaesu! It's clear now. Also, thank for the super quick response

<!-- gh-comment-id:3694852924 --> @thedevdavid commented on GitHub (Dec 28, 2025): Thanks, @bytaesu! It's clear now. Also, thank for the super quick response
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19330