[GH-ISSUE #6881] Password Change Issue #27986

Closed
opened 2026-04-17 19:18:26 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @er-santosh on GitHub (Dec 19, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6881

Note: Organization plugin is used.

  1. Try to change password with the following code below
  const onSubmit = async (data: ChangePasswordInput) => {
    await authClient.changePassword(
      {
        currentPassword: data.currentPassword,
        newPassword: data.newPassword,
        revokeOtherSessions: true,
      },
      {
        onSuccess() {
          toast.success("Password changed successfully");
          form.reset();
        },
        onError({ error }) {
          toast.error(error.message || "Password changed failed");
        },
      }
    );
  };

2.You will be logged out of the session and when you try to login again the active organization is not available in session table.

Originally created by @er-santosh on GitHub (Dec 19, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6881 Note: Organization plugin is used. 1. Try to change password with the following code below ``` const onSubmit = async (data: ChangePasswordInput) => { await authClient.changePassword( { currentPassword: data.currentPassword, newPassword: data.newPassword, revokeOtherSessions: true, }, { onSuccess() { toast.success("Password changed successfully"); form.reset(); }, onError({ error }) { toast.error(error.message || "Password changed failed"); }, } ); }; ``` 2.You will be logged out of the session and when you try to login again the active organization is not available in session table.
GiteaMirror added the lockedbug labels 2026-04-17 19:18:26 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 19, 2025):

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

This is expected behavior with the organization plugin: after a password change with revokeOtherSessions: true, all sessions are revoked and the session state—including the active organization context—is cleared. The organization plugin does not automatically restore the active organization when a new session is created; this is left to your application logic for flexibility.

To ensure the active organization is set after login or session recreation, add a session.create.before hook in your databaseHooks config to set activeOrganizationId when a session is created. For example:

databaseHooks: {
  session: {
    create: {
      before: async (session) => {
        // Query for the user's default or first organization
        const membership = await db.member.findFirst({
          where: { userId: session.userId },
          orderBy: { createdAt: 'asc' }
        });
        return {
          data: {
            ...session,
            activeOrganizationId: membership?.organizationId,
          },
        };
      },
    },
  },
}

This will automatically set the active organization in the session after login or session recreation. For more details and discussion, see this thread and this example. This is not a bug, but a design decision to let you control how organization context is managed across sessions.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3675627811 --> @dosubot[bot] commented on GitHub (Dec 19, 2025): <!-- Greeting --> Hi @er-santosh! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is expected behavior with the organization plugin: after a password change with `revokeOtherSessions: true`, all sessions are revoked and the session state—including the active organization context—is cleared. The organization plugin does not automatically restore the active organization when a new session is created; this is left to your application logic for flexibility. To ensure the active organization is set after login or session recreation, add a `session.create.before` hook in your `databaseHooks` config to set `activeOrganizationId` when a session is created. For example: ```ts databaseHooks: { session: { create: { before: async (session) => { // Query for the user's default or first organization const membership = await db.member.findFirst({ where: { userId: session.userId }, orderBy: { createdAt: 'asc' } }); return { data: { ...session, activeOrganizationId: membership?.organizationId, }, }; }, }, }, } ``` This will automatically set the active organization in the session after login or session recreation. For more details and discussion, see [this thread](https://github.com/better-auth/better-auth/issues/2309) and [this example](https://github.com/better-auth/better-auth/issues/3233). This is not a bug, but a design decision to let you control how organization context is managed across sessions. <!-- 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/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5d6c9949-8557-43ea-bb78-dc86dc32682a?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20expected%20behavior%20with%20the%20organization%20plugin%3A%20after%20a%20password%20change%20with%20%60revokeOtherSessions%3A%20true%60%2C%20all%20sessions%20are%20revoked%20and%20the%20session%20state%E2%80%94including%20the%20active%20organization%20context%E2%80%94is%20cleared.%20The%20organization%20plugin%20does%20not%20automatically%20restore%20the%20active%20organization%20when%20a%20new%20session%20is%20created%3B%20this%20is%20left%20to%20your%20application%20logic%20for%20flexibility.%20%0A%0ATo%20ensure%20the%20active%20organization%20is%20set%20after%20login%20or%20session%20recreation%2C%20add%20a%20%60session.create.before%60%20hook%20in%20your%20%60databaseHooks%60%20config%20to%20set%20%60activeOrganizationId%60%20when%20a%20session%20is%20created.%20For%20example%3A%0A%0A%60%60%60ts%0AdatabaseHooks%3A%20%7B%0A%20%20session%3A%20%7B%0A%20%20%20%20create%3A%20%7B%0A%20%20%20%20%20%20before%3A%20async%20%28session%29%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20//%20Query%20for%20the%20user%27s%20default%20or%20first%20organization%0A%20%20%20%20%20%20%20%20const%20membership%20%3D%20await%20db.member.findFirst%28%7B%0A%20%20%20%20%20%20%20%20%20%20where%3A%20%7B%20userId%3A%20session.userId%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20orderBy%3A%20%7B%20createdAt%3A%20%27asc%27%20%7D%0A%20%20%20%20%20%20%20%20%7D%29%3B%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20data%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20...session%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20activeOrganizationId%3A%20membership%3F.organizationId%2C%0A%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%7D%2C%0A%20%20%7D%2C%0A%7D%0A%60%60%60%0A%0AThis%20will%20automatically%20set%20the%20active%20organization%20in%20the%20session%20after%20login%20or%20session%20recreation.%20For%20more%20details%20and%20discussion%2C%20see%20%5Bthis%20thread%5D%28https%3A//github.com/better-auth/better-auth/issues/2309%29%20and%20%5Bthis%20example%5D%28https%3A//github.com/better-auth/better-auth/issues/3233%29.%20This%20is%20not%20a%20bug%2C%20but%20a%20design%20decision%20to%20let%20you%20control%20how%20organization%20context%20is%20managed%20across%20sessions.)&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/6881)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27986