BA
Better Auth•2mo ago
James!

Infer additional organization fields on react client not working?

When accessing the useActiveOrganization hook, the additional fields are not showing. The backend is working as expected for inserting the additional fields, however frontend inferrence is not working. I am getting a Property 'type' does not exist on type Prettify<{ ...core org fields }>
organization({
schema: {
organization: {
modelName: "organization",
fields: {
id: "id",
name: "name",
slug: "slug",
type: "type",
createdAt: "created_at",
updatedAt: "updated_at",
},
additionalFields: {
type: {
type: "string" as const,
fieldName: "type",
returned: true,
input: true,
required: true,
}
},
}
},
... other table mappings
})

// The plugins I pass to the react client
plugins: [
// Ensures all extra fields are added to the client
inferAdditionalFields<typeof auth>(), // <~ Should infer
organizationClient(),
// Also tried adding
// organizationClient({
// $inferAuth: auth,
// }),
],
organization({
schema: {
organization: {
modelName: "organization",
fields: {
id: "id",
name: "name",
slug: "slug",
type: "type",
createdAt: "created_at",
updatedAt: "updated_at",
},
additionalFields: {
type: {
type: "string" as const,
fieldName: "type",
returned: true,
input: true,
required: true,
}
},
}
},
... other table mappings
})

// The plugins I pass to the react client
plugins: [
// Ensures all extra fields are added to the client
inferAdditionalFields<typeof auth>(), // <~ Should infer
organizationClient(),
// Also tried adding
// organizationClient({
// $inferAuth: auth,
// }),
],
Any ideas? Is this a bug?
10 Replies
Ping
Ping•2mo ago
@James! Do this instead:
organizationClient({ $inferAuth: {} as typeof auth })
organizationClient({ $inferAuth: {} as typeof auth })
The inferAdditionalFields does not include organization ones.
James!
James!OP•2mo ago
strange I tried this and it still doesn't work 🤷 I am stripped of time so I did a dirty workaround for now: type: (org as any).type as string, The functionality itself works as intended and returns the value, it's just the TS. Perhaps it's due to my local env, I did try remove all node_modules & re-install + restart TS server + refresh window
Ping
Ping•2mo ago
@James! Can you show me your auth config? I'd like to repro because it's possible it's an issue on better-auth's end
James!
James!OP•2mo ago
Hey @Ping Relevant packages
"better-auth": "1.3.1",
"typescript": "^5.7.3",
"better-auth": "1.3.1",
"typescript": "^5.7.3",
The auth config (see attached message.txt)
Alejandro Montes
Alejandro Montes•2mo ago
Thanks, it worked for me. I was looking for this since the documentation was indicating to import a "inferOrgAdditionalFields" that I couldn't find a way to import. (https://www.better-auth.com/docs/plugins/organization#additional-fields)
Ping
Ping•2mo ago
You might need to upgrade to latest, my example is for older versions.
Alejandro Montes
Alejandro Montes•2mo ago
I just upgraded to the latest version this week. I double-checked and updating from 1.3.2 to 1.3.4 solve the inferOrgAdditionalFields import, but maybe was my node_modules not getting up to date. Still, on the docs it shows import { inferOrgAdditionalFields, organizationClient } from "better-auth/plugins/organization/client", which is not possible to import. Imported from "better-auth/client/plugins";
Alejandro Montes
Alejandro Montes•2mo ago
I opened an issue, hopefully it is not a mistake from my side. https://github.com/better-auth/better-auth/issues/3733
GitHub
Docs update: import instructions for additional fields in organizat...
Is this suited for github? Yes, this is suited for github To Reproduce Going to this part of the docs: https://www.better-auth.com/docs/plugins/organization#additional-fields In the section of infe...
Ping
Ping•2mo ago
Just upgraded to latest on my end with a test project, works fine for me, might be a node_modules thing.
import { inferOrgAdditionalFields } from "better-auth/client/plugins";
import { inferOrgAdditionalFields } from "better-auth/client/plugins";
Oh, the docs must have the wrong import I'll fix it
Alejandro Montes
Alejandro Montes•2mo ago
I think it was my case too. Thanks a lot!

Did you find this page helpful?