Create organiztion with KeepCurrentActiveOrganization=true is not working #1571

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

Originally created by @Kalyankr on GitHub (Jul 24, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

when creating a new organization with keepCurrentActiveOrganization flag to true, session is not updated with active Organization

values: {
name: string;
slug: string;
logo?: any;
}

const result = await authClient.organization.create({
...values,
keepCurrentActiveOrganization: true,
});

Current vs. Expected behavior

Expected session will be update with new organizationID, but its null,

// Proceed to create the organization
const result = await authClient.organization.create({
...values,
keepCurrentActiveOrganization: true,
});

  await authClient.organization.setActive({
    organizationId: result.data?.id,
  });

is working as expected.

What version of Better Auth are you using?

1.2.12

Provide environment information

OS : Ubuntu 24 LTS
Bowser : firefox

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

Backend

Auth config (if applicable)

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

Additional context

No response

Originally created by @Kalyankr on GitHub (Jul 24, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce when creating a new organization with keepCurrentActiveOrganization flag to true, session is not updated with active Organization values: { name: string; slug: string; logo?: any; } const result = await authClient.organization.create({ ...values, keepCurrentActiveOrganization: true, }); ### Current vs. Expected behavior Expected session will be update with new organizationID, but its null, // Proceed to create the organization const result = await authClient.organization.create({ ...values, keepCurrentActiveOrganization: true, }); await authClient.organization.setActive({ organizationId: result.data?.id, }); is working as expected. ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash OS : Ubuntu 24 LTS Bowser : firefox ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
Author
Owner

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

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

The behavior you're seeing is actually intended: when you set keepCurrentActiveOrganization to true, Better Auth will keep the current active organization in the session and will NOT switch to the newly created one. If you want the new organization to become active, you should either omit the flag or set it to false. If you need to activate the new org after creation, calling organization.setActive with the new org's ID (as you did) is the correct workaround. The flag's semantics are a bit confusing and not well documented, but your experience matches the code's design—this isn't a bug in v1.2.12.
Reference: code and discussion

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 (Jul 24, 2025): <!-- Greeting --> Hi @Kalyankr! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The behavior you're seeing is actually intended: when you set keepCurrentActiveOrganization to true, Better Auth will keep the current active organization in the session and will NOT switch to the newly created one. If you want the new organization to become active, you should either omit the flag or set it to false. If you need to activate the new org after creation, calling organization.setActive with the new org's ID (as you did) is the correct workaround. The flag's semantics are a bit confusing and not well documented, but your experience matches the code's design—this isn't a bug in v1.2.12. [Reference: code and discussion](https://github.com/better-auth/better-auth/blob/01814c55e0392ab09f990444fd5e9d5ab81d9e56/packages/better-auth/src/plugins/organization/routes/crud-org.ts) <!-- 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/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a2d2f05b-5f31-48ba-b4e5-02bc5861f4dd?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/3591)
Author
Owner

@Kalyankr commented on GitHub (Aug 1, 2025):

Got you, thank you @dosu

@Kalyankr commented on GitHub (Aug 1, 2025): Got you, thank you @dosu
Author
Owner

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

You're welcome!

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 --> You're welcome! <!-- 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/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/95cd6265-8795-4b68-907f-85750a882aa8?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/3591)
Author
Owner

@AntonVishal commented on GitHub (Aug 11, 2025):

@Kalyankr I think you are correct, it is a bug even I am facing this.

The bot's response was wrong

@AntonVishal commented on GitHub (Aug 11, 2025): @Kalyankr I think you are correct, it is a bug even I am facing this. The bot's response was wrong
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1571