-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
AdditionalFields break organization plugin and auth api #5122
Description
Is this suited for github?
- Yes, this is suited for github
To Reproduce
- Add organization plugin with additionalFields
Current vs. Expected behavior
I should be able to use createOrganization but because I'm using additionalFields in the organization typescript says createOrganization does not exist
What version of Better Auth are you using?
1.3.26
System info
{
"system": {
"platform": "win32",
"arch": "x64",
"version": "Windows 11 Pro",
"release": "10.0.26100",
"cpuCount": 12,
"cpuModel": "AMD Ryzen 5 5600X 6-Core Processor ",
"totalMemory": "15.91 GB",
"freeMemory": "4.04 GB"
},
"node": {
"version": "v22.16.0",
"env": "development"
},
"packageManager": {
"name": "npm",
"version": "11.2.0"
},
"frameworks": null,
"databases": null,
"betterAuth": {
"version": "Unknown",
"config": null
}
}Which area(s) are affected? (Select all that apply)
Types
Auth config (if applicable)
import { db } from "@repo/db";
import { corsOptions } from "@repo/types";
import { type BetterAuthOptions, betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import {
admin,
lastLoginMethod,
type OrganizationOptions,
openAPI,
organization,
twoFactor,
} from "better-auth/plugins";
const schema = {
organization: {
additionalFields: {
type: {
type: "string",
required: true,
fieldName: "type",
input: true,
returned: true,
},
locationId: {
type: "string",
fieldName: "location_id",
required: false,
input: true,
references: {
field: "id",
model: "locations",
onDelete: "set null",
},
returned: true,
},
},
},
team: {
additionalFields: {
type: {
type: "string",
required: true,
fieldName: "type",
input: true,
returned: true,
},
teamManagerId: {
type: "string",
fieldName: "team_manager_id",
required: true,
input: true,
returned: true,
},
},
},
} satisfies NonNullable<OrganizationOptions["schema"]>;
const organizationConfig = {
membershipLimit: 100, // Optional
teams: {
enabled: true,
maximumTeams: 10, // Optional: limit teams per organization
maximumMembersPerTeam: 10, // Optional: limit members per team
allowRemovingAllTeams: false, // Optional: prevent removing the last team
},
schema,
} satisfies OrganizationOptions;
type AuthPlugins = [
ReturnType<typeof organization<typeof organizationConfig>>,
ReturnType<typeof admin>,
ReturnType<typeof openAPI>,
ReturnType<typeof lastLoginMethod>,
ReturnType<typeof twoFactor>,
];
const plugins: AuthPlugins = [
organization(organizationConfig),
admin(),
openAPI(),
lastLoginMethod(),
twoFactor(),
] satisfies AuthPlugins;
const authConfig = {
appName: "Lanci",
emailAndPassword: {
enabled: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // Cache duration in seconds
},
},
plugins,
database: drizzleAdapter(db, {
provider: "pg",
}),
trustedOrigins: corsOptions.origin,
advanced: {
useSecureCookies: process.env.NODE_ENV === "production",
},
} satisfies BetterAuthOptions;
export const auth = betterAuth(authConfig) as ReturnType<
typeof betterAuth<typeof authConfig>
>;Additional context
Property 'createOrganization' does not exist on type 'InferAPI<{ readonly ok: { (inputCtx_0?: ({ body?: undefined; } & { method?: "GET" | undefined; } & { query?: Record<string, any> | undefined; } & { params?: Record<string, any> | undefined; } & { ...; } & { ...; } & { ...; } & { ...; }) | und...'.ts(2339)
const orgResult = await auth.api.createOrganization({ body: { name: data.organizationName, slug, type: "delivery", metadata: JSON.stringify({ phone: data.phone, website: data.website, address: { street: data.streetAddress, city: data.city, state: data.state, postalCode: data.postalCode, country: data.country, }, }), }, headers, });