Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

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

Carlos Monastyrskibb14231d711a
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.ts
index 6a3456508f..1f986bb728 100644
--- a/backend/src/services/auth/auth-login-service.ts
+++ b/backend/src/services/auth/auth-login-service.ts
@@ -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}`