Skip to content

Commit f92cd95

Browse files
fix: membership check
1 parent 54a6ed4 commit f92cd95

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

backend/src/services/auth/auth-login-service.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,20 @@ export const authLoginServiceFactory = ({
536536
const user = await userDAL.findUserEncKeyByUserId(decodedToken.userId);
537537
if (!user) throw new BadRequestError({ message: "User not found", name: "Find user from token" });
538538

539+
// Check user membership in the sub-organization
540+
const orgMembership = await membershipUserDAL.findOne({
541+
actorUserId: user.id,
542+
scopeOrgId: organizationId,
543+
scope: AccessScope.Organization,
544+
status: OrgMembershipStatus.Accepted
545+
});
546+
547+
if (!orgMembership) {
548+
throw new ForbiddenRequestError({
549+
message: `User does not have access to the organization with ID ${organizationId}`
550+
});
551+
}
552+
539553
const selectedOrg = await orgDAL.findById(organizationId);
540554
if (!selectedOrg) {
541555
throw new NotFoundError({ message: `Organization with ID '${organizationId}' not found` });
@@ -552,20 +566,6 @@ export const authLoginServiceFactory = ({
552566
});
553567
}
554568

555-
// Check user membership in the sub-organization
556-
const orgMembership = await membershipUserDAL.findOne({
557-
actorUserId: user.id,
558-
scopeOrgId: organizationId,
559-
scope: AccessScope.Organization,
560-
status: OrgMembershipStatus.Accepted
561-
});
562-
563-
if (!orgMembership) {
564-
throw new ForbiddenRequestError({
565-
message: `User does not have access to the sub-organization named ${selectedOrg.name}`
566-
});
567-
}
568-
569569
// Check user membership in the root organization
570570
const rootOrgMembership = await membershipUserDAL.findOne({
571571
actorUserId: user.id,

0 commit comments

Comments
 (0)