Organization: Determine what team a user belongs to
As the title implies, are members supposed to have a
teamId
associated to the model so that we can determine what team they belong to within an organization? I don't believe I see a teamId
associated to the model.
This is important as, when I fetch the full organization information, I want to be able to create team buckets but I cannot do that if I do not know what teamId
values a member is associated with.
Solution:Jump to solution
The teamId conditional inference is inverted so it was being inferred when teams were not enabled and not inferred when teams were enabled
I have made a pr to fix this https://github.com/better-auth/better-auth/pull/2133...
GitHub
fix(organization): fix inverted teamId inference in conditional typ...
Fixes incorrect teamId inferrence in InferMember and InferInvitation, where teamId was being inferred on type when teams where not enabled and omitted when teams were enabled
8 Replies
The teamId is present in the db schema for the
member
and invitation
tables, but the docs have not yet been updated to include this.
You can reference the internal schema of the organization plugin here https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/organization/schema.ts
I came across this pr which updates the teams schema https://github.com/better-auth/better-auth/pull/1640GitHub
better-auth/packages/better-auth/src/plugins/organization/schema.ts...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Gotcha -- what I'm hitting on is I think there is an issue with the
getFullOrganization
API as when I use the inferred typing from TypeScript, I get the following:
Each member
struct doesn't include a teamId
even though I have teams enabled for my Organization plugin so I cannot filter out and group members by what teams they belong to.can you check if the teams array of object is being inferenced in the returntype of
getFullOrganization
Yeah, the teams object is defined as
teams: Team[]
which translates into:
Solution
The teamId conditional inference is inverted so it was being inferred when teams were not enabled and not inferred when teams were enabled
I have made a pr to fix this https://github.com/better-auth/better-auth/pull/2133
GitHub
fix(organization): fix inverted teamId inference in conditional typ...
Fixes incorrect teamId inferrence in InferMember and InferInvitation, where teamId was being inferred on type when teams where not enabled and omitted when teams were enabled
Excellent! Slowly but surely, the Organization plugin will become more robust
Looking forward to all the holes being fixed
@MaveriX89 Can I mark this as solved?
@Ping yeah, since that PR is merged, feel free. I’m assuming the next release will have the fix