Skip to content

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

fix inconsistencies

Thiago Araujo da Silva7aa90df84d80
diff --git a/frontend/src/components/auth/Mfa.tsx b/frontend/src/components/auth/Mfa.tsx
index f27b727b0f..cadc3b6735 100644
--- a/frontend/src/components/auth/Mfa.tsx
+++ b/frontend/src/components/auth/Mfa.tsx
@@ -411,6 +411,23 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Prop
</div>
</form>
)}
+ {method === MfaMethod.EMAIL && !showRecoveryCodeInput && (
+ <div className="mx-auto flex max-h-24 w-full max-w-md flex-col items-center justify-center pt-2">
+ <div className="flex flex-row items-baseline gap-1 text-sm">
+ <span className="text-bunker-400">{t("signup.step2-resend-alert")}</span>
+ <div className="text-md mt-2 flex flex-row text-bunker-400">
+ <button disabled={isLoadingResend} onClick={handleResendMfaCode} type="button">
+ <span className="cursor-pointer duration-200 hover:text-bunker-200 hover:underline hover:decoration-primary-700 hover:underline-offset-4">
+ {isLoadingResend
+ ? t("signup.step2-resend-progress")
+ : t("signup.step2-resend-submit")}
+ </span>
+ </button>
+ </div>
+ </div>
+ <p className="pb-2 text-sm text-bunker-400">{t("signup.step2-spam-alert")}</p>
+ </div>
+ )}
{(method === MfaMethod.EMAIL ||
method === MfaMethod.TOTP ||
method === MfaMethod.WEBAUTHN) && (
@@ -457,23 +474,6 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Prop
</div>
</div>
)}
- {method === MfaMethod.EMAIL && !showRecoveryCodeInput && (
- <div className="mx-auto flex max-h-24 w-full max-w-md flex-col items-center justify-center pt-2">
- <div className="flex flex-row items-baseline gap-1 text-sm">
- <span className="text-bunker-400">{t("signup.step2-resend-alert")}</span>
- <div className="text-md mt-2 flex flex-row text-bunker-400">
- <button disabled={isLoadingResend} onClick={handleResendMfaCode} type="button">
- <span className="cursor-pointer duration-200 hover:text-bunker-200 hover:underline hover:decoration-primary-700 hover:underline-offset-4">
- {isLoadingResend
- ? t("signup.step2-resend-progress")
- : t("signup.step2-resend-submit")}
- </span>
- </button>
- </div>
- </div>
- <p className="pb-2 text-sm text-bunker-400">{t("signup.step2-spam-alert")}</p>
- </div>
- )}
</div>
);
};
diff --git a/frontend/src/components/mfa/MfaEnrollment.tsx b/frontend/src/components/mfa/MfaEnrollment.tsx
index 7c50e2d9d6..767857b755 100644
--- a/frontend/src/components/mfa/MfaEnrollment.tsx
+++ b/frontend/src/components/mfa/MfaEnrollment.tsx
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "react";
+import { TriangleAlertIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import SecurityClient from "@app/components/utilities/SecurityClient";
@@ -22,9 +23,12 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {
const { mutateAsync: updateUserMfa } = useUpdateUserMfa();
const [phase, setPhase] = useState<"preparing" | "verify" | "recovery">("preparing");
const [recoveryCodes, setRecoveryCodes] = useState<string[]>([]);
+ const [isLoadingCodes, setIsLoadingCodes] = useState(false);
const [hasDownloaded, setHasDownloaded] = useState(false);
const hasPrepared = useRef(false);
+ const hasRecoveryCodes = recoveryCodes.length > 0;
+
useEffect(() => {
if (hasPrepared.current) return;
hasPrepared.current = true;
@@ -49,15 +53,25 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {
prepare();
}, [updateUserMfa]);
+ const loadRecoveryCodes = async () => {
+ setIsLoadingCodes(true);
+ try {
+ setRecoveryCodes(await fetchMfaRecoveryCodes());
+ } catch {
+ setRecoveryCodes([]);
+ } finally {
+ setIsLoadingCodes(false);
+ }
+ };
+
const handleVerified = async () => {
try {
await updateUserMfa({ selectedMfaMethod: method });
} catch {
// preference update is best-effort
}
- const codes = await fetchMfaRecoveryCodes();
- setRecoveryCodes(codes);
setPhase("recovery");
+ await loadRecoveryCodes();
};
const handleContinue = async () => {
@@ -79,23 +93,49 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {
{phase === "verify" && <VerifyStep method={method} onVerified={handleVerified} />}
- {phase === "recovery" && (
- <div className="flex flex-col gap-4">
- <Alert variant="warning">
- <AlertTitle>Save your recovery codes</AlertTitle>
- <AlertDescription>
- Store these somewhere safe. Each works once if you lose access to your other methods.
- </AlertDescription>
- </Alert>
- <RecoveryCodesView
- recoveryCodes={recoveryCodes}
- onDownloaded={() => setHasDownloaded(true)}
- />
- <Button variant="org" isFullWidth isDisabled={!hasDownloaded} onClick={handleContinue}>
- Continue
- </Button>
- </div>
- )}
+ {phase === "recovery" &&
+ (isLoadingCodes ? (
+ <ContentLoader />
+ ) : (
+ <div className="flex flex-col gap-4">
+ {hasRecoveryCodes ? (
+ <>
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertTitle>Save your recovery codes</AlertTitle>
+ <AlertDescription>
+ Store these somewhere safe. Each works once if you lose access to your other
+ methods.
+ </AlertDescription>
+ </Alert>
+ <RecoveryCodesView
+ recoveryCodes={recoveryCodes}
+ onDownloaded={() => setHasDownloaded(true)}
+ />
+ </>
+ ) : (
+ <Alert variant="danger">
+ <TriangleAlertIcon />
+ <AlertTitle>Couldn&apos;t load recovery codes</AlertTitle>
+ <AlertDescription className="flex flex-col items-start gap-3">
+ Two-factor authentication is enabled, but we couldn&apos;t retrieve your recovery
+ codes. Generate them before continuing so you don&apos;t get locked out.
+ <Button variant="outline" size="sm" onClick={loadRecoveryCodes}>
+ Try again
+ </Button>
+ </AlertDescription>
+ </Alert>
+ )}
+ <Button
+ variant="org"
+ isFullWidth
+ isDisabled={!hasRecoveryCodes || !hasDownloaded}
+ onClick={handleContinue}
+ >
+ Continue
+ </Button>
+ </div>
+ ))}
</div>
);
};
diff --git a/frontend/src/hooks/api/users/mutation.tsx b/frontend/src/hooks/api/users/mutation.tsx
index cdd86f7e53..cb9e0b0f3d 100644
--- a/frontend/src/hooks/api/users/mutation.tsx
+++ b/frontend/src/hooks/api/users/mutation.tsx
@@ -77,6 +77,7 @@ export const useVerifyUserTotpRegistration = () => {
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: userKeys.totpConfiguration });
+ queryClient.removeQueries({ queryKey: userKeys.totpRegistration });
}
});
};
@@ -112,6 +113,7 @@ export const useDeleteUserTotpConfiguration = () => {
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: userKeys.totpConfiguration });
+ queryClient.removeQueries({ queryKey: userKeys.totpRegistration });
}
});
};
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
index 8ba1a5d05c..1f5b6b00c2 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
@@ -85,7 +85,11 @@ export const MFASection = () => {
...(totpConfiguration?.isVerified ? [MfaMethod.TOTP] : []),
...(webAuthnCredentials.length > 0 ? [MfaMethod.WEBAUTHN] : [])
];
- const selectedMethod = user.selectedMfaMethod || MfaMethod.EMAIL;
+
+ const preferredMethod = user.selectedMfaMethod || MfaMethod.EMAIL;
+ const selectedMethod = availableMethods.includes(preferredMethod)
+ ? preferredMethod
+ : availableMethods[0];
const handlePreferredMethodChange = async (method: MfaMethod) => {
try {
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaSetupWizard/MfaSetupWizard.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaSetupWizard/MfaSetupWizard.tsx
index bfacf23ba6..3ecfb4cc08 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaSetupWizard/MfaSetupWizard.tsx
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaSetupWizard/MfaSetupWizard.tsx
@@ -37,9 +37,13 @@ export const MfaSetupWizard = ({ isOpen, onOpenChange }: Props) => {
const [selectedMethod, setSelectedMethod] = useState<MfaMethod>(MfaMethod.TOTP);
const [hasDownloaded, setHasDownloaded] = useState(false);
- const { data: recoveryCodes = [], isPending: isRecoveryCodesLoading } = useGetMfaRecoveryCodes(
- isOpen && step === 2
- );
+ const {
+ data: recoveryCodes = [],
+ isFetching: isRecoveryCodesFetching,
+ refetch: refetchRecoveryCodes
+ } = useGetMfaRecoveryCodes(isOpen && step === 2);
+
+ const hasRecoveryCodes = recoveryCodes.length > 0;
useEffect(() => {
if (!isOpen) {
@@ -101,26 +105,41 @@ export const MfaSetupWizard = ({ isOpen, onOpenChange }: Props) => {
<MethodStep selectedMethod={selectedMethod} onSelect={setSelectedMethod} />
)}
{step === 1 && <VerifyStep method={selectedMethod} onVerified={handleVerified} />}
- {step === 2 && (
- <div className="flex flex-col gap-4">
- <Alert variant="warning">
- <TriangleAlertIcon />
- <AlertTitle>Save your recovery codes</AlertTitle>
- <AlertDescription>
- Store these somewhere safe. Each code works once and lets you sign in if you lose
- access to your other methods.
- </AlertDescription>
- </Alert>
- {isRecoveryCodesLoading ? (
- <ContentLoader />
- ) : (
- <RecoveryCodesView
- recoveryCodes={recoveryCodes}
- onDownloaded={() => setHasDownloaded(true)}
- />
- )}
- </div>
- )}
+ {step === 2 &&
+ (isRecoveryCodesFetching ? (
+ <ContentLoader />
+ ) : (
+ <div className="flex flex-col gap-4">
+ {hasRecoveryCodes ? (
+ <>
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertTitle>Save your recovery codes</AlertTitle>
+ <AlertDescription>
+ Store these somewhere safe. Each code works once and lets you sign in if you
+ lose access to your other methods.
+ </AlertDescription>
+ </Alert>
+ <RecoveryCodesView
+ recoveryCodes={recoveryCodes}
+ onDownloaded={() => setHasDownloaded(true)}
+ />
+ </>
+ ) : (
+ <Alert variant="danger">
+ <TriangleAlertIcon />
+ <AlertTitle>Couldn&apos;t load recovery codes</AlertTitle>
+ <AlertDescription className="flex flex-col items-start gap-3">
+ Two-factor authentication is enabled, but we couldn&apos;t retrieve your
+ recovery codes. Generate them before closing so you don&apos;t get locked out.
+ <Button variant="outline" size="sm" onClick={() => refetchRecoveryCodes()}>
+ Try again
+ </Button>
+ </AlertDescription>
+ </Alert>
+ )}
+ </div>
+ ))}
</div>
<SheetFooter className="items-center justify-between border-t">
@@ -139,7 +158,11 @@ export const MfaSetupWizard = ({ isOpen, onOpenChange }: Props) => {
</Button>
)}
{step === 2 && (
- <Button variant="org" isDisabled={!hasDownloaded} onClick={handleDone}>
+ <Button
+ variant="org"
+ isDisabled={!hasRecoveryCodes || !hasDownloaded}
+ onClick={handleDone}
+ >
Done
</Button>
)}