Update active organization if updated #569

Closed
opened 2026-03-13 07:53:24 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @undefinedhuman on GitHub (Jan 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use the "Organization" plugin, create a new orgaization and use this code:

const updateOrganization = () => {
  authClient.organization.update({
    data: {
      name: teamDto.value.name
    }
  });
};

And use the following const organizations = authClient.useListOrganizations(); to get a list of all organization (for me it is used to have a selection mechanism for the active organization)

Current vs. Expected behavior

Currently if I update the name of an organization it's not invalidating/refetching the list of organizations which is then not correlty displaying the updated name.

Expected:

Refetch the active + list of organizations once there was an update.

What version of Better Auth are you using?

1.1.13

Provide environment information

Tested with:

- OS: Manjaro Linux & macos 
- Firefox, Chrome

- NodeJS backend & Vue frontend

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

Client

Auth config (if applicable)

export const authClient = createAuthClient({
  plugins: [organizationClient(), usernameClient()]
});

export const auth = betterAuth({
    trustedOrigins: ["http://localhost:5173"],
    database: new pkg.Pool({
      host: DATABASE_HOST,
      port: DATABASE_PORT,
      user: DATABASE_USERNAME,
      password: DATABASE_PASSWORD,
      database: DATABASE_NAME
    }),
    databaseHooks: {
      user: {
        create: {
          after: async (user: any) => {
            try {
              await auth.api.createOrganization({
                body: {
                  name: `${user.username}'s`,
                  slug: `${user.username}s`,
                  userId: user.id
                }
              });
            } catch (error) {
              logger.error(error);
            }
          }
        }
      }
    },
    socialProviders: {
      github: {
        clientId: AUTH_GITHUB_ID,
        clientSecret: AUTH_GITHUB_SECRET,
        mapProfileToUser: (profile) => {
          return {
            username: profile.login
          };
        }
      }
    },
    plugins: [
      organization({
        allowUserToCreateOrganization: true
      }),
      username()
    ]
  });

Additional context

If you need more context, please let me know!

Originally created by @undefinedhuman on GitHub (Jan 16, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use the "Organization" plugin, create a new orgaization and use this code: ``` const updateOrganization = () => { authClient.organization.update({ data: { name: teamDto.value.name } }); }; ``` And use the following `const organizations = authClient.useListOrganizations();` to get a list of all organization (for me it is used to have a selection mechanism for the active organization) ### Current vs. Expected behavior Currently if I update the name of an organization it's not invalidating/refetching the list of organizations which is then not correlty displaying the updated name. Expected: Refetch the active + list of organizations once there was an update. ### What version of Better Auth are you using? 1.1.13 ### Provide environment information ```bash Tested with: - OS: Manjaro Linux & macos - Firefox, Chrome - NodeJS backend & Vue frontend ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript export const authClient = createAuthClient({ plugins: [organizationClient(), usernameClient()] }); export const auth = betterAuth({ trustedOrigins: ["http://localhost:5173"], database: new pkg.Pool({ host: DATABASE_HOST, port: DATABASE_PORT, user: DATABASE_USERNAME, password: DATABASE_PASSWORD, database: DATABASE_NAME }), databaseHooks: { user: { create: { after: async (user: any) => { try { await auth.api.createOrganization({ body: { name: `${user.username}'s`, slug: `${user.username}s`, userId: user.id } }); } catch (error) { logger.error(error); } } } } }, socialProviders: { github: { clientId: AUTH_GITHUB_ID, clientSecret: AUTH_GITHUB_SECRET, mapProfileToUser: (profile) => { return { username: profile.login }; } } }, plugins: [ organization({ allowUserToCreateOrganization: true }), username() ] }); ``` ### Additional context If you need more context, please let me know!
GiteaMirror added the bug label 2026-03-13 07:53:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#569