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.
No description
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
Jump to solution
8 Replies
Netrifier
Netrifier3w ago
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/1640
GitHub
better-auth/packages/better-auth/src/plugins/organization/schema.ts...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
MaveriX89
MaveriX89OP3w ago
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:
members: {
id: string;
organizationId: string;
role: "member" | "admin" | "owner";
createdAt: Date;
userId: string;
user: {
email: string;
name: string;
image?: string;
};
}[];
members: {
id: string;
organizationId: string;
role: "member" | "admin" | "owner";
createdAt: Date;
userId: string;
user: {
email: string;
name: string;
image?: string;
};
}[];
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.
Netrifier
Netrifier3w ago
can you check if the teams array of object is being inferenced in the returntype of getFullOrganization
MaveriX89
MaveriX89OP3w ago
Yeah, the teams object is defined as teams: Team[] which translates into:
teams: {
id: string;
name: string;
createdAt: Date;
organizationId: string;
updatedAt?: Date | undefined;
}[]
teams: {
id: string;
name: string;
createdAt: Date;
organizationId: string;
updatedAt?: Date | undefined;
}[]
Solution
Netrifier
Netrifier3w ago
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
MaveriX89
MaveriX89OP3w ago
Excellent! Slowly but surely, the Organization plugin will become more robust Looking forward to all the holes being fixed
Ping
Ping3w ago
@MaveriX89 Can I mark this as solved?
MaveriX89
MaveriX89OP3w ago
@Ping yeah, since that PR is merged, feel free. I’m assuming the next release will have the fix

Did you find this page helpful?