BA
Better Auth•3w ago
Maqed

Plugin to extend organization plugin

Hello everyone 👋 I'm building a plugin to extend organizations by making sub-organizations. The idea is that I want to extend organization schema to include sub-organizations to make it one-to-many (one organization to many sub-organization) how can I achieve such thing? I'm thinking of auth.ts:
import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins"
import {subOrganization} from "./subOrganization"

const auth = betterAuth({
plugins: [
organization({
schema: {
organization: {
fields: {
name: "subOrganizationId"
}
}
}
}),
subOrganization({
// ...
})
]
})
import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins"
import {subOrganization} from "./subOrganization"

const auth = betterAuth({
plugins: [
organization({
schema: {
organization: {
fields: {
name: "subOrganizationId"
}
}
}
}),
subOrganization({
// ...
})
]
})
subOrganization.ts
import type { BetterAuthPlugin } from "better-auth";

export const subOrganization= ()=>{
return {
id: "subOrganization",
schema: {
organization: {
fields: {
name: "organizationId"
}
}
}
// rest of the subOrganization logic
} satisfies BetterAuthPlugin
}
import type { BetterAuthPlugin } from "better-auth";

export const subOrganization= ()=>{
return {
id: "subOrganization",
schema: {
organization: {
fields: {
name: "organizationId"
}
}
}
// rest of the subOrganization logic
} satisfies BetterAuthPlugin
}
I don't really like this implementation as I think it would be better If I could handle all of the schema logic inside my subOrganization plugin. Is there any way better than this to handle it? thank you in advance
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?