Repository: Infisical/infisical
File: frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OrgGeneralAuthSection.tsx (TypeScript)

Code before:

        await logout.mutateAsync();
        window.open(`/api/v1/sso/redirect/saml2/organizations/${currentOrg.slug}`);
        window.close();
      } else if (enforcementTypeInModal === EnforceAuthType.GOOGLE) {
        await mutateAsync({
          orgId: currentOrg?.id,
          googleSsoAuthEnforced: true
        });

        createNotification({
          text: "Successfully enabled org-level Google SSO enforcement",
          type: "success"
        });

        handlePopUpToggle("enforceSamlSsoConfirmation", false);
        setBypassEnabledInModal(false);
        setEnforcementTypeInModal(null);

        await logout.mutateAsync();
        window.open(`/api/v1/sso/redirect/google?org_slug=${currentOrg.slug}`);
        window.close();
      }
    } catch (err) {
      console.error(err);
      createNotification({
        text: `Failed to enable ${enforcementTypeInModal === EnforceAuthType.SAML ? "SAML" : "Google"} SSO enforcement`,
        type: "error"
      });
    }
  };

  const handleEnforceOrgAuthToggle = async (value: boolean, type: EnforceAuthType) => {
    if (!currentOrg?.id) return;

    if (type === EnforceAuthType.SAML) {
      if (!subscription?.samlSSO) {
        handlePopUpOpen("upgradePlan");
        return;
      }

      if (value) {
        setBypassEnabledInModal(currentOrg?.bypassOrgAuthEnabled ?? false);
        setEnforcementTypeInModal(EnforceAuthType.SAML);
        handlePopUpOpen("enforceSamlSsoConfirmation");
        return;
      }

      await mutateAsync({
        orgId: currentOrg?.id,
        authEnforced: value

Review comment (bug):
not sure we need this notification as the mutation creates one on failure
<img width="850" height="540" alt="CleanShot 2025-12-17 at 11 54 14@2x" src="https://github.com/user-attachments/assets/b9a7d122-ee83-41bd-b960-d4b2ae15c86d" />


Code after:

        await logout.mutateAsync();
        window.open(`/api/v1/sso/redirect/saml2/organizations/${currentOrg.slug}`);
        window.close();
      } else if (enforcementTypeInModal === EnforceAuthType.GOOGLE) {
        await mutateAsync({
          orgId: currentOrg?.id,
          googleSsoAuthEnforced: true
        });

        createNotification({
          text: "Successfully enabled org-level Google SSO enforcement",
          type: "success"
        });

        handlePopUpToggle("enforceSamlSsoConfirmation", false);
        setBypassEnabledInModal(false);
        setEnforcementTypeInModal(null);

        await logout.mutateAsync();
        window.open(`/api/v1/sso/redirect/google?org_slug=${currentOrg.slug}`);
        window.close();
      }
    } catch (err) {
      console.error(err);
    }
  };

  const handleEnforceOrgAuthToggle = async (value: boolean, type: EnforceAuthType) => {
    if (!currentOrg?.id) return;

    if (type === EnforceAuthType.SAML) {
      if (!subscription?.samlSSO) {
        handlePopUpOpen("upgradePlan");
        return;
      }

      if (value) {
        setBypassEnabledInModal(currentOrg?.bypassOrgAuthEnabled ?? false);
        setEnforcementTypeInModal(EnforceAuthType.SAML);
        handlePopUpOpen("enforceSamlSsoConfirmation");
        return;
      }

      await mutateAsync({
        orgId: currentOrg?.id,
        authEnforced: value
      });

      createNotification({
        text: "Successfully disabled org-level SAML SSO enforcement",