Throw an error when org authEnforced is enabled and user is trying to select org

This commit is contained in:
Carlos Monastyrski
2025-08-18 11:06:11 +08:00
parent 8a72023e80
commit bb14231d71

View File

@@ -451,6 +451,13 @@ export const authLoginServiceFactory = ({
const hasOrganizationMembership = userOrgs.some((org) => org.id === organizationId && org.userStatus !== "invited");
const selectedOrg = await orgDAL.findById(organizationId);
// Check if authEnforced is true, if that's the case, throw an error
if (selectedOrg.authEnforced) {
throw new BadRequestError({
message: "Authentication is required by your organization before you can log in."
});
}
if (!hasOrganizationMembership) {
throw new ForbiddenRequestError({
message: `User does not have access to the organization named ${selectedOrg?.name}`