BA
Better Authโ€ข2w ago
danchez

Organization: OrganizationClient does not seem to add interfaces to authClient

I am attempting to configure the Organization Plugin using Better Auth 1.3.7. I have the following server/client configuration:
// server/lib/auth.ts
const { ac, roles } = OrganizationPluginOptions;

const betterAuthOptions = {
database: drizzleAdapter(db, {
provider: "pg",
schema: {
user: AuthUserTable,
account: AuthAccountTable,
session: AuthSessionTable,
verification: AuthVerificationTable,
organization: AuthOrganizationTable,
member: AuthOrganizationMemberTable,
team: AuthTeamTable,
teamMember: AuthTeamMemberTable,
invitation: AuthInvitationTable,
},
}),
advanced: {
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
plugins: [
admin(),
organization({
ac,
roles,
allowUserToCreateOrganization: false,
teams: {
enabled: true,
allowRemovingAllTeams: false,
},
}),
],
}

export const auth = betterAuth(betterAuthOptions);

export type ServerAuth = typeof auth;
// server/lib/auth.ts
const { ac, roles } = OrganizationPluginOptions;

const betterAuthOptions = {
database: drizzleAdapter(db, {
provider: "pg",
schema: {
user: AuthUserTable,
account: AuthAccountTable,
session: AuthSessionTable,
verification: AuthVerificationTable,
organization: AuthOrganizationTable,
member: AuthOrganizationMemberTable,
team: AuthTeamTable,
teamMember: AuthTeamMemberTable,
invitation: AuthInvitationTable,
},
}),
advanced: {
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
plugins: [
admin(),
organization({
ac,
roles,
allowUserToCreateOrganization: false,
teams: {
enabled: true,
allowRemovingAllTeams: false,
},
}),
],
}

export const auth = betterAuth(betterAuthOptions);

export type ServerAuth = typeof auth;
And here is the client:
import { OrganizationPluginOptions } from "@org/rbac";
import type { ServerAuth } from "@org/server/lib/auth";
import { createAuthClient } from "better-auth/client";
import { adminClient, inferAdditionalFields, organizationClient } from "better-auth/client/plugins";

const { ac, roles } = OrganizationPluginOptions;

export const authClient = createAuthClient({
baseURL: window.location.origin,
plugins: [
organizationClient({
ac,
roles,
teams: { enabled: true, allowRemovingAllTeams: false },
}),
inferAdditionalFields<ServerAuth>(),
],
});
import { OrganizationPluginOptions } from "@org/rbac";
import type { ServerAuth } from "@org/server/lib/auth";
import { createAuthClient } from "better-auth/client";
import { adminClient, inferAdditionalFields, organizationClient } from "better-auth/client/plugins";

const { ac, roles } = OrganizationPluginOptions;

export const authClient = createAuthClient({
baseURL: window.location.origin,
plugins: [
organizationClient({
ac,
roles,
teams: { enabled: true, allowRemovingAllTeams: false },
}),
inferAdditionalFields<ServerAuth>(),
],
});
With the above config, when I attempt to use authClient.organization I only see checkRolePermission as an available API and none of the other organization APIs (i.e. hasPermission, listMembers, etc.). What is going on here?
45 Replies
danchez
danchezOPโ€ข2w ago
@Better Auth what can you tell me about this post?
Better Auth
Better Authโ€ข2w ago
Hi there! Could you please clarify which post you're referring to? There have been several posts and commits about Better Authโ€”from dependency updates [1] to specific provider patches [16]. Let me know which one you mean, and I'll be happy to help! Sources: [1] fix(deps): update better-auth dependencies [16] twitter patch
GitHub
fix(deps): update better-auth dependencies by renovate[bot] ยท Pull...
This PR contains the following updates: Package Change Age Confidence @better-auth/utils 0.2.5 -&amp;gt; 0.2.6 @simplewebauthn/browser (source) ^13.0.0 -&amp;gt; ^13.1.2 โ€ฆ
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
twitter patch by dagmawibabi ยท Pull Request #3485 ยท better-auth/b...
Fixed: #3481 This pull request includes a small update to the twitter function in packages/better-auth/src/social-providers/twitter.ts. The change updates the authentication method from &amp;quot;...
Ping
Pingโ€ข2w ago
Is it intentional to import createAuthClient from better-auth/client rather than better-auth/react?
danchez
danchezOPโ€ข2w ago
I'm using SolidJS in my case. I tried /solid and /client and both produce the same outcome. Also docs seem to specify using /client
Ping
Pingโ€ข2w ago
Oh, okay then use /client. let me keep digging further it looks like a monorepo project?
danchez
danchezOPโ€ข2w ago
Yeah, this is a monorepo project
Ping
Pingโ€ข2w ago
Can you test seeing any of the endpoint type definitions for both server & client auth in the same files they're respectively defined in? For example check that auth.api.createOrganization works in auth.ts and authClient.organization.create works in the auth-client.ts file
danchez
danchezOPโ€ข2w ago
The breakdown is the following:
@org/rbac: exports common {ac, roles} to configure Organization plugin across both server/client
@org/server: has better-auth server config (imports from rbac)
@org/web: frontend client that also imports from rbac
@org/rbac: exports common {ac, roles} to configure Organization plugin across both server/client
@org/server: has better-auth server config (imports from rbac)
@org/web: frontend client that also imports from rbac
Ping
Pingโ€ข2w ago
(I've seen cases where there can be missing types when inferred across packages, so just making sure there is nothing wrong with the auth client / auth config itself)
danchez
danchezOPโ€ข2w ago
Yeah, so when I inline type within my auth.ts module on the server end, I can see TypeScript bring up all the expected interfaces on the organization object which is good It's the client side that is missing all the APIs
Ping
Pingโ€ข2w ago
So even testing in the same file which you defined the createAuthClient you can't access any of the org types?
danchez
danchezOPโ€ข2w ago
Precisely. Sorry, I meant to say api object. So it's auth.api and all the available Organization APIs are present via TypeScript/Intellisense.
Ping
Pingโ€ข2w ago
If you were to comment out any of the organizationClient's passed options, would inference start working for the authClient?
danchez
danchezOPโ€ข2w ago
Tried that too with just a vanilla organizationClient() and still the same outcome. You can see from above that I even exported the ServerAuth type and tried to use inferAdditionalFields to see if that would fix anything. Still no dice.
Ping
Pingโ€ข2w ago
Just testing something as basic as this works on my end:
No description
Ping
Pingโ€ข2w ago
Could it be related to tsconfig in some way, or a incorrectly installed better-auth dependency?
danchez
danchezOPโ€ข2w ago
Let me try that same exact thing.
danchez
danchezOPโ€ข2w ago
Look at that weird behavior man
No description
danchez
danchezOPโ€ข2w ago
No description
Ping
Pingโ€ข2w ago
Try removing node_modules and re-installing Better-auth ๐Ÿค”
danchez
danchezOPโ€ข2w ago
Still the same outcome. I even went ahead and pinned the Better Auth version across all the packages:
"better-auth": "1.3.7",
"better-auth": "1.3.7",
I am using Turborepo and have the following clean script:
"clean": "turbo run clean && rimraf node_modules",
"clean": "turbo run clean && rimraf node_modules",
Each of the packages/apps clean scripts are the following:
"clean": "rimraf node_modules dist",
"clean": "rimraf node_modules dist",
I also nuked my bun.lock after cleaning to regenerate it after re-installing everything. Still the same outcome.
Ping
Pingโ€ข2w ago
Okay this is really werid, maybe there is some tsconfig value causing this. Could you sure your tsconfig? FYI, I'm not sure what's going on here, so we'll have to debug this ๐Ÿ˜…
danchez
danchezOPโ€ข2w ago
I just appreciate you being available to help. I normally try to be self-sufficient but this issue is making me pull my hair out cause I believe I'm doing everything right. I have the following root tsconfig:
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ESNext",
"module": "ESNext",
"allowJs": true,
"resolveJsonModule": true,
"moduleResolution": "Bundler",
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,
"checkJs": true,

"strict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
},
"exclude": ["**/node_modules", "**/coverage", "**/dist", "**/storybook-static"]
}
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ESNext",
"module": "ESNext",
"allowJs": true,
"resolveJsonModule": true,
"moduleResolution": "Bundler",
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,
"checkJs": true,

"strict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
},
"exclude": ["**/node_modules", "**/coverage", "**/dist", "**/storybook-static"]
}
Ping
Pingโ€ข2w ago
Do you require exactOptionalPropertyTypes?
danchez
danchezOPโ€ข2w ago
I can do without that. I'm fine with removing stuff
Ping
Pingโ€ข2w ago
I've seen issues with Better-Auth with this config flag in the past, so it could be related, though doubtful
danchez
danchezOPโ€ข2w ago
Got rid of it, no changes on the problem
Ping
Pingโ€ข2w ago
Do you have a public repo I check this out?
danchez
danchezOPโ€ข2w ago
Yeah, let me just push up the changes
danchez
danchezOPโ€ข2w ago
GitHub
GitHub - thedanchez/dm-poc
Contribute to thedanchez/dm-poc development by creating an account on GitHub.
danchez
danchezOPโ€ข2w ago
Try hitting that. I'm using Bun + Turborepo, so you should be able to do a bun install to get everything Just search for auth-client in the web package under the apps directory
Ping
Pingโ€ข2w ago
Awesome, will check it out now
Ping
Pingโ€ข2w ago
No description
danchez
danchezOPโ€ข2w ago
Really grateful. I'm curious if your machine will produce a different result
Ping
Pingโ€ข2w ago
Same issue, ๐Ÿ™ƒ
danchez
danchezOPโ€ข2w ago
Ah, so you're getting it there too
Ping
Pingโ€ข2w ago
I'll let you know if I find anything
danchez
danchezOPโ€ข2w ago
Glad I'm not crazy haha Maybe this will be a good issue to document once we find the root cause here
Ping
Pingโ€ข2w ago
I removed the extends from tsconfig and it was fixed There is a config value in there, maybe I can find it
danchez
danchezOPโ€ข2w ago
Incredible. Would not have expected a TSConfig value to have such a huge impact
Ping
Pingโ€ข2w ago
It was exactOptionalPropertyTypes ๐Ÿคฃ Try to add exactOptionalPropertyTypes: false and it should be fixed Yeah ๐Ÿ˜…
danchez
danchezOPโ€ข2w ago
WOW!! Yeah, this is definitely worth documenting My God...
Ping
Pingโ€ข2w ago
We hope to fix this in the future in the first place haha, but yeah I understand Glad it could be solved :)
danchez
danchezOPโ€ข2w ago
Thank you for spending the time debugging this with me Holy crap this was painful
DiamondDragon
DiamondDragonโ€ข6d ago
thanks for the thread i had this problem too. not the first time exactOptionalPropertyTypes has come up as causing issues though

Did you find this page helpful?