mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-30 06:04:15 -05:00
fix(organization): membership check for organizations with large member counts (#4724)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -707,9 +707,10 @@ export const getFullOrganization = <O extends OrganizationOptions>(
|
||||
message: ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
const isMember = organization?.members.find(
|
||||
(member) => member.userId === session.user.id,
|
||||
);
|
||||
const isMember = await adapter.checkMembership({
|
||||
userId: session.user.id,
|
||||
organizationId: organization.id,
|
||||
});
|
||||
if (!isMember) {
|
||||
await adapter.setActiveOrganization(session.session.token, null);
|
||||
throw new APIError("FORBIDDEN", {
|
||||
@@ -717,11 +718,6 @@ export const getFullOrganization = <O extends OrganizationOptions>(
|
||||
ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,
|
||||
});
|
||||
}
|
||||
if (!organization) {
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
type OrganizationReturn = O["teams"] extends { enabled: true }
|
||||
? {
|
||||
members: InferMember<O>[];
|
||||
|
||||
Reference in New Issue
Block a user