Typescript error in the better auth instance configuration when using organization()
The title explains most of it, here is the specific error message:
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; logo?: string | undefined; metadata?: Record<...> | undefined; keepCurrentActiveOrganization?: boolean | ...' 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; }'.ts(2322)
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; logo?: string | undefined; metadata?: Record<...> | undefined; keepCurrentActiveOrganization?: boolean | ...' 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; }'.ts(2322)
5 Replies
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
socialProviders: {
github: {
clientId: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
},
},
plugins: [
username(),
passkey(),
admin(),
multiSession(),
organization({
allowUserToCreateOrganization: true,
}),
oidcProvider({
loginPage: "/login",
}),
genericOAuth({
config: [],
}),
],
});
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
socialProviders: {
github: {
clientId: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
},
},
plugins: [
username(),
passkey(),
admin(),
multiSession(),
organization({
allowUserToCreateOrganization: true,
}),
oidcProvider({
loginPage: "/login",
}),
genericOAuth({
config: [],
}),
],
});
Below is the schema, this is automatically generated.
there is also a build error:
should i open an issue on the github repository?
src/auth.ts:41:9 - error TS2322: Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; logo?: string | undefined; metadata?: Record<...> | undefined; keepCurrentActiveOrganization?: boolean | ...' 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; }'.
41 organization({
~~~~~~~~~~~~~~
42 allowUserToCreateOrganization: true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43 }),
src/auth.ts:41:9 - error TS2322: Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; logo?: string | undefined; metadata?: Record<...> | undefined; keepCurrentActiveOrganization?: boolean | ...' 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; }'.
41 organization({
~~~~~~~~~~~~~~
42 allowUserToCreateOrganization: true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43 }),
Did you have any luck with this one?
Any update?