What is the type that returns auth.api.getFullOrganization()

@Better Auth What is the type that returns auth.api.getFullOrganization()? Can I explicitly define it, similar to export type Organization = typeof auth.$Infer.Organization;? it's defintly not that, because the full Org type sems to return a list of members
13 Replies
Better Auth
Better Auth4w ago
You can’t simply use the inferred organization type (i.e. auth.$Infer.Organization) because the data returned from auth.api.getFullOrganization includes additional details—in particular a members array (with detailed user information) that isn’t present in the shorthand inferred type [9]. Instead, many developers define the type explicitly by “extracting” the data from the API response. For example, you can do something like this:
export type FullOrganization =
NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>['data']>;
export type FullOrganization =
NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>['data']>;
This approach uses TypeScript’s utility types (Awaited and ReturnType) to infer exactly what the API returns at runtime. That way, you get a type that reflects the full organization data—including the members array—even though it isn’t the same as auth.$Infer.Organization [8][9]. In summary, while auth.$Infer.Organization is useful for many cases, for getFullOrganization you should define your FullOrganization type by extracting it from the API call as shown above. Sources: [8] Organizations: getFullOrganization() has incorrect example in docs. [9] Organization | Better Auth
GitHub
Organizations: getFullOrganization() has incorrect example in docs....
Currently in docs we have this: const organization = await authClient.organization.getFullOrganization({ organizationId: &quot;organization-id&quot; // optional, by default it will use the active o...
Organization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
michidk
michidkOP4w ago
@Better Auth Property 'data' does not exist on type '({ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; } & { ...; }) | null'.ts(2339)
Better Auth
Better Auth4w ago
It looks like you’re trying to access a property called data on an API response that doesn’t actually include a data field. In this case, the response is already an object containing properties like members and invitations (or it can be null) [1]. To fix the error, verify your API response’s structure and update your code accordingly. For example, if you’re expecting the members directly, you might do something like:
const response = await authClient.organization.getSomething();
if (response) {
const members = response.members;
// use members as needed
}
const response = await authClient.organization.getSomething();
if (response) {
const members = response.members;
// use members as needed
}
Or, if you’re unsure whether the response has the field, you can also use optional chaining:
const members = response?.members;
const members = response?.members;
This way, TypeScript knows you’re accounting for the possibility that the response might be null or different than what you expected. If you need further changes, check the Better Auth documentation to confirm the response format for the API you’re calling [1]. This error is similar to one reported in our GitHub issues where the TypeScript types indicated that the returned object might be null or have a different shape than expected. Sources: [1] [bug] Property 'data' does not exist
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
[bug] Property 'data' does not exist · Issue #1323 · better-auth/...
Is this suited for github? Yes, this is suited for github To Reproduce I&#39;m using authClient in an angular app. I did read typescript&#39;s concepts, but still getting the error: ✘ [ERROR] TS233...
michidk
michidkOP4w ago
@Better Auth I get this: Property 'data' does not exist on type '({ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; } & { ...; }) | null'.ts(2339) when trying to infer the type: export type Organization = typeof auth.$Infer.Organization; export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>['data']>;
Better Auth
Better Auth4w ago
It looks like the issue is caused because the response from the getFullOrganization API isn’t wrapped in a data property any longer. In other words, the API now returns the organization object (or null) directly, so trying to extract a .data property results in the TS2339 error [1]. To fix this, you can update your type inference to use the response directly. For example, change:
export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>['data']>;
export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>['data']>;
to
export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>>;
export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>>;
This way, your FullOrganization type directly represents the returned organization object. Make sure to check the documentation for any recent changes in the API response structure if you’re upgrading Better Auth versions [1]. Sources: [1] [bug] Property 'data' does not exist
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
[bug] Property 'data' does not exist · Issue #1323 · better-auth/...
Is this suited for github? Yes, this is suited for github To Reproduce I&#39;m using authClient in an angular app. I did read typescript&#39;s concepts, but still getting the error: ✘ [ERROR] TS233...
michidk
michidkOP4w ago
@Better Auth I dont think export type FullOrganization = NonNullable<Awaited<ReturnType<typeof auth.api.getFullOrganization>>>; can be used to type the return value of this api call as async (organizationId: string): Promise<FullOrganization> => { return await api.getFullOrganization({ headers: await headers(), query: { organizationId }, }); }, gives the following error: Type '({ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; } & { ...; }) | null' is not assignable to type '{ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; } & { ...; }'. Type 'null' is not assignable to type '{ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; } & { ...; }'. Type 'null' is not assignable to type '{ members: { id: string; organizationId: string; role: "admin" | "member"; createdAt: Date; userId: string; user: { email: string; name: string; image?: string | undefined; }; }[]; invitations: { ...; }[]; }'
Better Auth
Better Auth4w ago
The error is occurring because the API call for getFullOrganization may return null, whereas your FullOrganization type is defined as a non‑nullable object. In other words, by wrapping the return type in NonNullable, you’re asserting that getFullOrganization should never return null, which isn’t always guaranteed by the API [13]. You can handle this in a couple of ways: 1. Update your type or function signature to accept a potential null value. For example, you might declare the return type as Promise<FullOrganization | null> and add a null check before proceeding. 2. If you’re sure an organization should always be returned in your use case (for example, when the active organization is always set), you could assert the value isn’t null after performing a runtime check, or handle the null case explicitly. These approaches align with better practices in handling API data that might be missing expected values [13]. Sources: [13] Organization | Better Auth
Organization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
michidk
michidkOP4w ago
@Better Auth now, is there an api call to get a organization by id but not the full org?
Better Auth
Better Auth4w ago
Yes! You can use the new API endpoint that returns basic organization details rather than the full details. Specifically, use the GET /organization/get endpoint via the SDK method (i.e., authClient.organization.getOrganization), where you pass either an organizationId or an organizationSlug. This endpoint is designed to provide a minimal payload with just the essential organization information, unlike getFullOrganization which includes details like members, invitations, and teams [2]. Sources: [2] feat(org): get organization
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
feat(org): get organization by frectonz · Pull Request #4363 · be...
Done Implement getOrganization Document getOrganization Add tests for it Summary by cubic Add a lightweight GET /organization/get endpoint and SDK methods to fetch basic organization info by ID ...
michidk
michidkOP4w ago
@Better Auth a api.getOrganization does not seem to exist
Better Auth
Better Auth4w ago
Hi there! The api.getOrganization endpoint does exist—it was introduced as part of Better Auth’s organization functionality. You should be able to access it via the SDK as shown in our docs (it’s provided as auth.api.getOrganization and also available on the client through authClient.organization.getOrganization)[1]. If you aren’t seeing it, please ensure that: 1. You have the organization plugin enabled in your Better Auth configuration. 2. You’re using a version that includes this endpoint. 3. You're calling it correctly with the required parameters (e.g., either an organizationId or organizationSlug) and proper authentication headers. Double-check your setup against the plugin documentation to confirm everything is set up correctly. Let me know if you need any more help! Sources: [1] feat(org): get organization
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
feat(org): get organization by frectonz · Pull Request #4363 · be...
Done Implement getOrganization Document getOrganization Add tests for it Summary by cubic Add a lightweight GET /organization/get endpoint and SDK methods to fetch basic organization info by ID ...
michidk
michidkOP4w ago
@Better Auth no that is not true. this Pr is not yet merged: https://github.com/better-auth/better-auth/pull/4363
GitHub
feat(org): get organization by frectonz · Pull Request #4363 · be...
Done Implement getOrganization Document getOrganization Add tests for it Summary by cubic Add a lightweight GET /organization/get endpoint and SDK methods to fetch basic organization info by ID ...
Better Auth
Better Auth4w ago
Hey there! You're right – according to our records, PR #4363 is still open and hasn’t been merged yet. Many of our PRs (like several dependency updates) require a manual merge once they're verified, so this one is following the same process [1], [2]. Let us know if you have any other questions about our merge process or anything else related to Better Auth! Sources: [1] chore(deps): update better-auth dependencies (major) [2] chore(deps): update better-auth dependencies
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
chore(deps): update better-auth dependencies (major) by renovate[bo...
Coming soon: The Renovate bot (GitHub App) will be renamed to Mend. PRs from Renovate will soon appear from &amp;#39;Mend&amp;#39;. Learn more here. This PR contains the following updates: Packa...
GitHub
chore(deps): update better-auth dependencies by renovate[bot] · Pu...
This PR contains the following updates: Package Change Age Confidence @tanstack/react-start (source) ^1.131.3 -&amp;gt; ^1.131.26 hono (source) ^4.9.0 -&amp;gt; ^4.9.2 …

Did you find this page helpful?