[GH-ISSUE #2471] Property 'useActiveOrganization' does not exist on type. (Minimal Reproduction repo provided) #17839

Closed
opened 2026-04-15 16:10:51 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @gerkim62 on GitHub (Apr 29, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2471

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Minimal Reproduction Repo
main problematic file: src/app/page.tsx line 7.
other relevant files: src/lib/auth-client.ts and auth.ts

  1. Add organization plugin to auth config like so
const organizationPlugin: BetterAuthPlugin = organization() as BetterAuthPlugin;
const organizationAuthClient: BetterAuthClientPlugin =
  organizationClient() as BetterAuthClientPlugin;

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  trustedOrigins: [],
  emailAndPassword: {
    enabled: true,
  },
  plugins: [organizationPlugin, nextCookies()],
  user: {
    additionalFields: {},
  },
});
  1. Run:
npx @better-auth/cli generate
  1. Add the client plugin like so:
export const authClient = createAuthClient({
  plugins: [inferAdditionalFields<typeof auth>(), organizationAuthClient],
});
  1. In any client component, try calling:
const { data: activeOrganization } = authClient.useActiveOrganization();

It will throw this TypeScript error:

Property 'useActiveOrganization' does not exist on type '{ signIn: { social: <FetchOptions extends { method?: string; headers?: HeadersInit & (HeadersInit | CommonHeaders); cache?: RequestCache; credentials?: RequestCredentials; ... 31 more ...; disableValidation?: boolean; }>(data_0: Prettify<...>, data_1?: FetchOptions | undefined) => Promise<...>; }; } & ... 22 more .....'.ts(2339)

Current vs. Expected behavior

calling const { data: activeOrganization } = authClient.useActiveOrganization();
throws a typescript error instead of returning the active organization as expected

What version of Better Auth are you using?

"better-auth": "^1.2.7"

Provide environment information

Windows 11
Visual studio code
"typescript": "^5"

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

Client, Types, Documentation

Auth config (if applicable)

import { betterAuth, BetterAuthClientPlugin } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import prisma from "@/lib/prisma";
import {
  inferAdditionalFields,
  organizationClient,
} from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react"; // make sure to import from better-auth/react
import { nextCookies } from "better-auth/next-js";
import { organization, BetterAuthPlugin } from "better-auth/plugins";

// TODO: I hate to use the "as" operator here, but I don't know how to make it work without it.
const organizationPlugin: BetterAuthPlugin = organization() as BetterAuthPlugin;
const organizationAuthClient: BetterAuthClientPlugin =
  organizationClient() as BetterAuthClientPlugin;

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  trustedOrigins: [],
  emailAndPassword: {
    enabled: true,
  },
  plugins: [organizationPlugin, nextCookies()],
  user: {
    additionalFields: {},
  },
});

export const authClient = createAuthClient({
  plugins: [inferAdditionalFields<typeof auth>(), organizationAuthClient],
});

Additional context

it is returning null but typescript acts as if the authClient.useActiveOrganization(); does not exist

Originally created by @gerkim62 on GitHub (Apr 29, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2471 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce [Minimal Reproduction Repo](https://github.com/gerkim62/organization-issue-repro) main problematic file: src/app/page.tsx line 7. other relevant files: src/lib/auth-client.ts and auth.ts 1. Add organization plugin to auth config like so ```typescript const organizationPlugin: BetterAuthPlugin = organization() as BetterAuthPlugin; const organizationAuthClient: BetterAuthClientPlugin = organizationClient() as BetterAuthClientPlugin; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), trustedOrigins: [], emailAndPassword: { enabled: true, }, plugins: [organizationPlugin, nextCookies()], user: { additionalFields: {}, }, }); ``` 2. Run: ```bash npx @better-auth/cli generate ``` 3. Add the client plugin like so: ```typescript export const authClient = createAuthClient({ plugins: [inferAdditionalFields<typeof auth>(), organizationAuthClient], }); ``` 4. In any client component, try calling: ```typescript const { data: activeOrganization } = authClient.useActiveOrganization(); ``` It will throw this TypeScript error: ``` Property 'useActiveOrganization' does not exist on type '{ signIn: { social: <FetchOptions extends { method?: string; headers?: HeadersInit & (HeadersInit | CommonHeaders); cache?: RequestCache; credentials?: RequestCredentials; ... 31 more ...; disableValidation?: boolean; }>(data_0: Prettify<...>, data_1?: FetchOptions | undefined) => Promise<...>; }; } & ... 22 more .....'.ts(2339) ``` ### Current vs. Expected behavior calling `const { data: activeOrganization } = authClient.useActiveOrganization();` throws a typescript error instead of returning the active organization as expected ### What version of Better Auth are you using? "better-auth": "^1.2.7" ### Provide environment information ```bash Windows 11 Visual studio code "typescript": "^5" ``` ### Which area(s) are affected? (Select all that apply) Client, Types, Documentation ### Auth config (if applicable) ```typescript import { betterAuth, BetterAuthClientPlugin } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import prisma from "@/lib/prisma"; import { inferAdditionalFields, organizationClient, } from "better-auth/client/plugins"; import { createAuthClient } from "better-auth/react"; // make sure to import from better-auth/react import { nextCookies } from "better-auth/next-js"; import { organization, BetterAuthPlugin } from "better-auth/plugins"; // TODO: I hate to use the "as" operator here, but I don't know how to make it work without it. const organizationPlugin: BetterAuthPlugin = organization() as BetterAuthPlugin; const organizationAuthClient: BetterAuthClientPlugin = organizationClient() as BetterAuthClientPlugin; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), trustedOrigins: [], emailAndPassword: { enabled: true, }, plugins: [organizationPlugin, nextCookies()], user: { additionalFields: {}, }, }); export const authClient = createAuthClient({ plugins: [inferAdditionalFields<typeof auth>(), organizationAuthClient], }); ``` ### Additional context it is returning null but typescript acts as if the `authClient.useActiveOrganization();` does not exist
GiteaMirror added the locked label 2026-04-15 16:10:51 -05:00
Author
Owner

@gerkim62 commented on GitHub (Apr 29, 2025):

It turns out that all these is caused by having "exactOptionalPropertyTypes": true in my tsconfig. flipping it to false makes the errors go away and everything starts working, but it is still not as type safe as i would want it to be. this is still a workaround

<!-- gh-comment-id:2838909775 --> @gerkim62 commented on GitHub (Apr 29, 2025): It turns out that all these is caused by having `"exactOptionalPropertyTypes": true` in my tsconfig. flipping it to false makes the errors go away and everything starts working, but it is still not as type safe as i would want it to be. this is still a workaround
Author
Owner

@hugooliveirad commented on GitHub (Jun 5, 2025):

I've had the same issue with the organization better-auth/plugins. Pasting the issue related to organization here as it might be useful for someone (or something) searching for a solution:

When "exactOptionalPropertyTypes": true in my tsconfig, this error comes up when trying to use the organization plugin.

Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; metadata?: Record<string, any> | undefined; userId?: string | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'.
     Types of property 'schema' are incompatible.
       Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'.
         Property 'team' is incompatible with index signature.
           Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.
             Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'. [2322]

This is my auth config:

export const auth = betterAuth({
  baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3300',
  secret: Resource.BetterAuthSecret.value,
  emailAndPassword: {
    enabled: true,
    autoSignIn: true,
    minPasswordLength: 8,
  },
  basePath: '/api/v1/auth',
  database: drizzleAdapter(postgres, {
    provider: 'pg',
  }),
  plugins: [
    organization({
      ac,
      allowUserToCreateOrganization: true,
      membershipLimit: 1,
      teams: { enabled: false },
      roles: {
        // ... app specific
      },
    }),
    openAPI(),
  ],
})

Setting "exactOptionalPropertyTypes": false on my tsconfig.json fixes it. Here's the complete tsconfig.json for reference:

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "exactOptionalPropertyTypes": false,
    "noUncheckedIndexedAccess": true,
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "allowJs": false,
    "checkJs": false,
    "lib": [
      "ESNext"
    ],
    "types": [
      "node"
    ]
  },
  "include": [
    "sst-env.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}
<!-- gh-comment-id:2945015960 --> @hugooliveirad commented on GitHub (Jun 5, 2025): I've had the same issue with the `organization` `better-auth/plugins`. Pasting the issue related to organization here as it might be useful for someone (or something) searching for a solution: When `"exactOptionalPropertyTypes": true` in my tsconfig, this error comes up when trying to use the organization plugin. ``` Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; metadata?: Record<string, any> | undefined; userId?: string | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'. Types of property 'schema' are incompatible. Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'. Property 'team' is incompatible with index signature. Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'. Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'. [2322] ``` This is my auth config: ```ts export const auth = betterAuth({ baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3300', secret: Resource.BetterAuthSecret.value, emailAndPassword: { enabled: true, autoSignIn: true, minPasswordLength: 8, }, basePath: '/api/v1/auth', database: drizzleAdapter(postgres, { provider: 'pg', }), plugins: [ organization({ ac, allowUserToCreateOrganization: true, membershipLimit: 1, teams: { enabled: false }, roles: { // ... app specific }, }), openAPI(), ], }) ``` Setting `"exactOptionalPropertyTypes": false` on my `tsconfig.json` fixes it. Here's the complete tsconfig.json for reference: ```json { "compilerOptions": { "strict": true, "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "exactOptionalPropertyTypes": false, "noUncheckedIndexedAccess": true, "target": "ESNext", "module": "ESNext", "moduleResolution": "bundler", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "allowJs": false, "checkJs": false, "lib": [ "ESNext" ], "types": [ "node" ] }, "include": [ "sst-env.d.ts" ], "exclude": [ "node_modules" ] } ```
Author
Owner

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

I'm observing similar behavior with a comparable setup, but using Nuxt instead of Next.

Overriding the exactOptionalPropertyTypes option to false via the typescript setting in the Nuxt config does not seem to have any effect.

All organization-related functions are not properly typed and gives me a typescript errors. On the server side activeOrganisationId is also not typed on the server side session

I noticed this commit related to organization types, which might be connected to this issue.

<!-- gh-comment-id:3081623836 --> @mathieumagalhaes commented on GitHub (Jul 16, 2025): I'm observing similar behavior with a comparable setup, but using Nuxt instead of Next. Overriding the exactOptionalPropertyTypes option to false via the typescript setting in the Nuxt config does not seem to have any effect. All organization-related functions are not properly typed and gives me a typescript errors. On the server side activeOrganisationId is also not typed on the server side session I noticed [this commit](https://github.com/better-auth/better-auth/commit/de20ad60aa7df50d147d8e94f61ee99cb49709a2) related to organization types, which might be connected to this issue.
Author
Owner

@Kinfe123 commented on GitHub (Aug 3, 2025):

This issue arises from the extended @tsconfig/strictest config, which enables exactOptionalPropertyTypes by default and enforces stricter handling of optional fields. For now, setting this flag to false is a safe workaround. we’ll ship a proper fix after a more review of the affected typings.

<!-- gh-comment-id:3148715077 --> @Kinfe123 commented on GitHub (Aug 3, 2025): This issue arises from the extended `@tsconfig/strictest` config, which enables exactOptionalPropertyTypes by default and enforces stricter handling of optional fields. For now, setting this flag to false is a safe workaround. we’ll ship a proper fix after a more review of the affected typings.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17839