Skip to content

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

remove unused code

Thiago Araujo da Silva94b3a4a736cf
diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.ts
index 2d70b15b3c..c9d218339e 100644
--- a/backend/src/server/routes/v2/user-router.ts
+++ b/backend/src/server/routes/v2/user-router.ts
@@ -52,7 +52,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
})
}
},
- preHandler: verifyAuth([AuthMode.JWT, AuthMode.API_KEY], { requireOrg: false }),
+ preHandler: verifyAuth([AuthMode.JWT], { requireOrg: false }),
handler: async (req) => {
const user = await server.services.user.setSelectedMfaMethod({
userId: req.permission.id,
diff --git a/backend/src/services/mfa-recovery-code/mfa-recovery-code-service.ts b/backend/src/services/mfa-recovery-code/mfa-recovery-code-service.ts
index 02f3ea695c..2e05cb583d 100644
--- a/backend/src/services/mfa-recovery-code/mfa-recovery-code-service.ts
+++ b/backend/src/services/mfa-recovery-code/mfa-recovery-code-service.ts
@@ -1,5 +1,3 @@
-import { Knex } from "knex";
-
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
import { TKmsServiceFactory } from "../kms/kms-service";
@@ -7,7 +5,6 @@ import { TUserDALFactory } from "../user/user-dal";
import { TMfaRecoveryCodeDALFactory } from "./mfa-recovery-code-dal";
import { generateRecoveryCode } from "./mfa-recovery-code-fns";
import {
- TDeleteRecoveryCodesDTO,
TEnsureRecoveryCodesDTO,
TGetRecoveryCodesDTO,
TRotateRecoveryCodesDTO,
@@ -110,21 +107,7 @@ export const mfaRecoveryCodeServiceFactory = ({
const { recoveryCodes, encryptedRecoveryCodes } = generateEncryptedRecoveryCodes();
- const upsert = async (tx: Knex) => {
- const recoveryCodeConfig = await mfaRecoveryCodeDAL.findOne({ userId }, tx);
-
- if (recoveryCodeConfig) {
- await mfaRecoveryCodeDAL.updateById(recoveryCodeConfig.id, { encryptedRecoveryCodes }, tx);
- } else {
- await mfaRecoveryCodeDAL.create({ userId, encryptedRecoveryCodes }, tx);
- }
- };
-
- if (externalTx) {
- await upsert(externalTx);
- } else {
- await mfaRecoveryCodeDAL.transaction(upsert);
- }
+ await mfaRecoveryCodeDAL.upsert([{ userId, encryptedRecoveryCodes }], "userId", externalTx);
return recoveryCodes;
};
@@ -142,15 +125,10 @@ export const mfaRecoveryCodeServiceFactory = ({
return rotateRecoveryCodes({ userId, tx, skipMfaEnabledCheck: true });
};
- const deleteRecoveryCodes = async ({ userId, tx }: TDeleteRecoveryCodesDTO) => {
- await mfaRecoveryCodeDAL.delete({ userId }, tx);
- };
-
return {
getRecoveryCodes,
verifyAndConsumeRecoveryCode,
rotateRecoveryCodes,
- ensureRecoveryCodes,
- deleteRecoveryCodes
+ ensureRecoveryCodes
};
};
diff --git a/backend/src/services/mfa-recovery-code/mfa-recovery-code-types.ts b/backend/src/services/mfa-recovery-code/mfa-recovery-code-types.ts
index 9f34cf596b..d537a6a041 100644
--- a/backend/src/services/mfa-recovery-code/mfa-recovery-code-types.ts
+++ b/backend/src/services/mfa-recovery-code/mfa-recovery-code-types.ts
@@ -19,8 +19,3 @@ export type TEnsureRecoveryCodesDTO = {
userId: string;
tx?: Knex;
};
-
-export type TDeleteRecoveryCodesDTO = {
- userId: string;
- tx?: Knex;
-};
diff --git a/frontend/src/components/mfa/MfaEnrollment.tsx b/frontend/src/components/mfa/MfaEnrollment.tsx
index a9c29f0fe4..5c9011e410 100644
--- a/frontend/src/components/mfa/MfaEnrollment.tsx
+++ b/frontend/src/components/mfa/MfaEnrollment.tsx
@@ -2,7 +2,6 @@ import { useEffect, useRef, useState } from "react";
import { createNotification } from "@app/components/notifications";
import SecurityClient from "@app/components/utilities/SecurityClient";
-import { ContentLoader } from "@app/components/v2";
import { Button } from "@app/components/v3";
import { MfaMethod } from "@app/hooks/api/auth/types";
import { getMfaTempToken } from "@app/hooks/api/reactQuery";
@@ -21,7 +20,7 @@ type Props = {
// MFA -> save codes.
export const MfaEnrollment = ({ method, onComplete }: Props) => {
const { mutateAsync: activateMfa } = useActivateMfa();
- const [phase, setPhase] = useState<"preparing" | "verify" | "recovery">("preparing");
+ const [phase, setPhase] = useState<"verify" | "recovery">("verify");
const [recoveryCodes, setRecoveryCodes] = useState<string[]>([]);
const [hasSaved, setHasSaved] = useState(false);
const hasPrepared = useRef(false);
@@ -33,7 +32,6 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {
hasPrepared.current = true;
SecurityClient.setMfaToken("");
- setPhase("verify");
}, []);
const handleVerified = async (codes?: string[]) => {
@@ -64,8 +62,6 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {
</p>
</div>
- {phase === "preparing" && <ContentLoader />}
-
{phase === "verify" && <VerifyStep method={method} onVerified={handleVerified} />}
{phase === "recovery" && (
diff --git a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx b/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
index 367489be75..a0a656af13 100644
--- a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
+++ b/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
@@ -53,7 +53,7 @@ export const RecoveryCodesView = ({ recoveryCodes, onSaved }: Props) => {
<DownloadIcon /> Download
</Button>
<Button variant="outline" isFullWidth onClick={handleCopy}>
- <CopyIcon /> {copied ? "Copied!" : "Copy"}
+ <CopyIcon /> {copied ? "Copied" : "Copy"}
</Button>
</div>
</div>
diff --git a/frontend/src/components/mfa/setup/VerifyStep.tsx b/frontend/src/components/mfa/setup/VerifyStep.tsx
index 9536c25dee..70de04ff27 100644
--- a/frontend/src/components/mfa/setup/VerifyStep.tsx
+++ b/frontend/src/components/mfa/setup/VerifyStep.tsx
@@ -81,7 +81,7 @@ const TotpVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {
isDisabled={totp.trim().length !== 6}
onClick={handleVerify}
>
- Verify code
+ Verify Code
</Button>
</div>
);
@@ -137,7 +137,7 @@ const EmailVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {
isDisabled={code.trim().length !== 6}
onClick={handleVerify}
>
- Verify code
+ Verify Code
</Button>
</div>
</div>
@@ -176,7 +176,7 @@ const WebAuthnVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) =>
placeholder="Passkey name (optional)"
/>
<Button variant="org" isPending={isRegistering} onClick={handleRegister}>
- <FingerprintIcon /> Register passkey
+ <FingerprintIcon /> Register Passkey
</Button>
</div>
);
diff --git a/frontend/src/hooks/api/users/index.tsx b/frontend/src/hooks/api/users/index.tsx
index 7102a96bda..fbf37d732c 100644
--- a/frontend/src/hooks/api/users/index.tsx
+++ b/frontend/src/hooks/api/users/index.tsx
@@ -6,8 +6,7 @@ export {
useRevokeMySessionById,
useSendEmailVerificationCode,
useUpdateUserEmail,
- useVerifyCurrentEmailOTP,
- useVerifyUserTotpRegistration
+ useVerifyCurrentEmailOTP
} from "./mutation";
export {
fetchOrgUsers,
diff --git a/frontend/src/hooks/api/users/mutation.tsx b/frontend/src/hooks/api/users/mutation.tsx
index a07f162279..c3856fd7c8 100644
--- a/frontend/src/hooks/api/users/mutation.tsx
+++ b/frontend/src/hooks/api/users/mutation.tsx
@@ -65,23 +65,6 @@ export const useUpdateUserProjectFavorites = () => {
});
};
-export const useVerifyUserTotpRegistration = () => {
- const queryClient = useQueryClient();
- return useMutation<{ success: boolean }, unknown, { totp: string }>({
- mutationFn: async ({ totp }: { totp: string }) => {
- const { data } = await apiRequest.post<{ success: boolean }>("/api/v1/user/me/totp/verify", {
- totp
- });
-
- return data;
- },
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: userKeys.totpConfiguration });
- queryClient.removeQueries({ queryKey: userKeys.totpRegistration });
- }
- });
-};
-
export const useDeleteUserTotpConfiguration = () => {
const queryClient = useQueryClient();
return useMutation({
diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsx
index 54113effbf..72e58f37e9 100644
--- a/frontend/src/hooks/api/users/queries.tsx
+++ b/frontend/src/hooks/api/users/queries.tsx
@@ -11,6 +11,7 @@ import { MfaMethod } from "../auth/types";
import { TGroupWithProjectMemberships } from "../groups/types";
import { setAuthToken } from "../reactQuery";
import { subscriptionQueryKeys } from "../subscriptions/queries";
+import { webAuthnKeys } from "../webauthn/queries";
import { userKeys } from "./query-keys";
import {
AddUserToOrgDTO,
@@ -435,6 +436,9 @@ export const useEnrollMfa = () => {
onSuccess() {
queryClient.invalidateQueries({ queryKey: userKeys.getUser });
queryClient.invalidateQueries({ queryKey: userKeys.totpConfiguration });
+ // Enrollment is method-agnostic; a WEBAUTHN enroll adds a credential, so
+ // keep the passkey list in sync regardless of the method used.
+ queryClient.invalidateQueries({ queryKey: webAuthnKeys.credentials });
}
});
};
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
index 9d225475d3..9eb73a5825 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
@@ -84,6 +84,8 @@ export const MFASection = () => {
const hasConfiguredFactor =
Boolean(totpConfiguration?.isVerified) || webAuthnCredentials.length > 0;
+ const hasRecoveryCodes = hasConfiguredFactor || user.isMfaEnabled;
+
const handleEnable = async () => {
if (!hasConfiguredFactor) {
setIsWizardOpen(true);
@@ -125,8 +127,8 @@ export const MFASection = () => {
}
};
- const disabledView = (
- <div className="mb-6 rounded-lg border border-border bg-card p-6">
+ const disabledBanner = (
+ <div className="rounded-lg border border-border bg-card p-6">
<div className="flex items-start justify-between">
<h2 className="text-lg font-medium text-foreground">Two-factor Authentication</h2>
<Badge variant="danger">
@@ -153,68 +155,69 @@ export const MFASection = () => {
</div>
);
- const enabledView = (
- <div className="mb-6 flex flex-col gap-6">
- <div className="rounded-lg border border-border bg-card p-6">
- <div className="flex items-start justify-between">
- <h2 className="text-lg font-medium text-foreground">Two-factor Authentication</h2>
- <Badge variant="success">
- <ShieldCheckIcon /> Enabled
- </Badge>
- </div>
- <p className="mt-2 max-w-2xl text-sm text-muted">
- Two-factor authentication is protecting your account. Manage your methods and recovery
- options below.
- </p>
-
- <div className="mt-6 border-t border-border pt-6">
- <p className="text-sm font-medium text-foreground">Preferred 2FA method</p>
- <p className="mb-3 text-sm text-muted">
- Set the method used first when signing in to Infisical.
- </p>
- <div className="max-w-xs">
- <Select
- value={selectedMethod}
- onValueChange={(value) => handlePreferredMethodChange(value as MfaMethod)}
- >
- <SelectTrigger className="w-full">
- <SelectValue placeholder="Select a method" />
- </SelectTrigger>
- <SelectContent>
- {availableMethods.map((method) => {
- const Icon = MFA_METHOD_ICONS[method];
- return (
- <SelectItem key={method} value={method}>
- <span className="flex items-center gap-2">
- <Icon />
- {MFA_METHOD_LABELS[method]}
- </span>
- </SelectItem>
- );
- })}
- </SelectContent>
- </Select>
- </div>
- </div>
+ const enabledBanner = (
+ <div className="rounded-lg border border-border bg-card p-6">
+ <div className="flex items-start justify-between">
+ <h2 className="text-lg font-medium text-foreground">Two-factor Authentication</h2>
+ <Badge variant="success">
+ <ShieldCheckIcon /> Enabled
+ </Badge>
+ </div>
+ <p className="mt-2 max-w-2xl text-sm text-muted">
+ Two-factor authentication is protecting your account. Manage your methods and recovery
+ options below.
+ </p>
- <div className="mt-6 flex items-center justify-between gap-4 border-t border-border pt-6">
- <p className="text-sm text-muted">
- {isMfaEnforced
- ? "Your organization requires two-factor authentication, so it can't be disabled."
- : "Turning this off keeps your configured methods and recovery codes so you can re-enable it later."}
- </p>
- <Button
- variant="danger"
- isDisabled={isMfaEnforced}
- onClick={() => setIsDisableOpen(true)}
+ <div className="mt-6 border-t border-border pt-6">
+ <p className="text-sm font-medium text-foreground">Preferred 2FA method</p>
+ <p className="mb-3 text-sm text-muted">
+ Set the method used first when signing in to Infisical.
+ </p>
+ <div className="max-w-xs">
+ <Select
+ value={selectedMethod}
+ onValueChange={(value) => handlePreferredMethodChange(value as MfaMethod)}
>
- <PowerIcon /> Disable two-factor authentication
- </Button>
+ <SelectTrigger className="w-full">
+ <SelectValue placeholder="Select a method" />
+ </SelectTrigger>
+ <SelectContent>
+ {availableMethods.map((method) => {
+ const Icon = MFA_METHOD_ICONS[method];
+ return (
+ <SelectItem key={method} value={method}>
+ <span className="flex items-center gap-2">
+ <Icon />
+ {MFA_METHOD_LABELS[method]}
+ </span>
+ </SelectItem>
+ );
+ })}
+ </SelectContent>
+ </Select>
</div>
</div>
- <MfaMethodsCard />
- <RecoveryOptionsCard />
+ <div className="mt-6 flex items-center justify-between gap-4 border-t border-border pt-6">
+ <p className="text-sm text-muted">
+ {isMfaEnforced
+ ? "Your organization requires two-factor authentication, so it can't be disabled."
+ : "Turning this off keeps your configured methods and recovery codes so you can re-enable it later."}
+ </p>
+ <Button variant="danger" isDisabled={isMfaEnforced} onClick={() => setIsDisableOpen(true)}>
+ <PowerIcon /> Disable two-factor authentication
+ </Button>
+ </div>
+ </div>
+ );
+
+ return (
+ <>
+ <div className="mb-6 flex flex-col gap-6">
+ {user.isMfaEnabled ? enabledBanner : disabledBanner}
+ <MfaMethodsCard />
+ {hasRecoveryCodes && <RecoveryOptionsCard />}
+ </div>
<AlertDialog open={isDisableOpen} onOpenChange={setIsDisableOpen}>
<AlertDialogContent>
@@ -233,14 +236,9 @@ export const MFASection = () => {
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
- </div>
- );
- return (
- <>
- {user.isMfaEnabled ? enabledView : disabledView}
{/* Mounted at a stable position so enabling MFA mid-wizard (which flips the
- view above) does not unmount the dialog and interrupt the flow. */}
+ banner above) does not unmount the dialog and interrupt the flow. */}
<MfaSetupWizard isOpen={isWizardOpen} onOpenChange={setIsWizardOpen} />
</>
);