Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
remove email verification
Thiago Araujo da Silvaa732eab40815
diff --git a/backend/src/db/migrations/20260701120200_add-mfa-recovery-codes.ts b/backend/src/db/migrations/20260701120200_add-mfa-recovery-codes.tsindex 7968b7bd5b..5999d493db 100644--- a/backend/src/db/migrations/20260701120200_add-mfa-recovery-codes.ts+++ b/backend/src/db/migrations/20260701120200_add-mfa-recovery-codes.ts@@ -31,36 +31,37 @@ export async function up(knex: Knex): Promise<void> {);}- // Recovery codes now live in user_mfa_recovery_codes; TOTP no longer writes- // this column. Make it nullable so new TOTP configs can omit it. A follow-up- // migration can drop the column entirely.+ // Recovery codes now live in user_mfa_recovery_codes. The values were copied+ // above, so drop the legacy column from totp_configs.if (await knex.schema.hasColumn(TableName.TotpConfig, "encryptedRecoveryCodes")) {await knex.schema.alterTable(TableName.TotpConfig, (t) => {- t.binary("encryptedRecoveryCodes").nullable().alter();+ t.dropColumn("encryptedRecoveryCodes");});}}export async function down(knex: Knex): Promise<void> {- // Re-populate the TOTP column from the account-level store before restoring- // the NOT NULL constraint so rollback does not fail on existing rows.+ // Recreate the legacy column so the pre-migration TOTP code can read recovery+ // codes again. It is nullable because TOTP configs created after the column+ // was dropped have no ciphertext to restore (their codes only live in the+ // account-level store, which may have no row for a given user).+ if (!(await knex.schema.hasColumn(TableName.TotpConfig, "encryptedRecoveryCodes"))) {+ await knex.schema.alterTable(TableName.TotpConfig, (t) => {+ t.binary("encryptedRecoveryCodes").nullable();+ });+ }+if (await knex.schema.hasTable(TableName.UserMfaRecoveryCode)) {+ // Copy the account-level recovery codes back into the freshly recreated+ // column. Both stores share the same root-key ciphertext, so it is portable.await knex.raw(`UPDATE ?? tcSET "encryptedRecoveryCodes" = rc."encryptedRecoveryCodes"FROM ?? rc- WHERE tc."userId" = rc."userId" AND tc."encryptedRecoveryCodes" IS NULL`,+ WHERE tc."userId" = rc."userId"`,[TableName.TotpConfig, TableName.UserMfaRecoveryCode]);- }- if (await knex.schema.hasColumn(TableName.TotpConfig, "encryptedRecoveryCodes")) {- await knex.schema.alterTable(TableName.TotpConfig, (t) => {- t.binary("encryptedRecoveryCodes").notNullable().alter();- });- }-- if (await knex.schema.hasTable(TableName.UserMfaRecoveryCode)) {await dropOnUpdateTrigger(knex, TableName.UserMfaRecoveryCode);await knex.schema.dropTable(TableName.UserMfaRecoveryCode);}diff --git a/backend/src/db/schemas/totp-configs.ts b/backend/src/db/schemas/totp-configs.tsindex 2ec06b5233..d7fbbc571c 100644--- a/backend/src/db/schemas/totp-configs.ts+++ b/backend/src/db/schemas/totp-configs.ts@@ -13,7 +13,6 @@ export const TotpConfigsSchema = z.object({id: z.string().uuid(),userId: z.string().uuid(),isVerified: z.boolean().default(false),- encryptedRecoveryCodes: zodBuffer.nullable().optional(),encryptedSecret: zodBuffer,createdAt: z.date(),updatedAt: z.date()diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 594d1a483a..a0d08f4111 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -125,7 +125,6 @@ export const KeyStorePrefixes = {EmailSignupOtpHash: (hash: string) => `email-signup-otp:${hash}:hash` as const,EmailSignupOtpLock: (hash: string) => `email-signup-otp:${hash}:lock` as const,EmailSignupResendCooldown: (hash: string) => `email-signup-otp:${hash}:cd` as const,- MfaEmailSetupResendCooldown: (userId: string) => `mfa-email-setup:${userId}:cd` as const,InsightsCache: (projectId: string, endpoint: string) => `insights-cache:${projectId}:${endpoint}` as const,AdminConfig: "infisical-admin-cfg",@@ -165,7 +164,6 @@ export const KeyStoreTtls = {RefreshTokenGraceInSeconds: 10,EmailSignupOtpInSeconds: 300, // 5 minutesEmailSignupResendCooldownInSeconds: 60, // 1 minute- MfaEmailSetupResendCooldownInSeconds: 60, // 1 minuteInsightsCacheInSeconds: 300, // 5 minutesInsightsDuplicationCacheInSeconds: 3600, // 1 hourAdminConfigInSeconds: 60,diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex bca91e2bfd..405ddcc41d 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -1176,7 +1176,6 @@ export const registerRoutes = async (membershipUserDAL,totpConfigDAL,webAuthnCredentialDAL,- keyStore,mfaRecoveryCodeService});diff --git a/backend/src/server/routes/v1/user-router.ts b/backend/src/server/routes/v1/user-router.tsindex b87383e77e..c2b5e55ef6 100644--- a/backend/src/server/routes/v1/user-router.ts+++ b/backend/src/server/routes/v1/user-router.ts@@ -333,56 +333,6 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {}});- server.route({- method: "POST",- url: "/me/mfa/email/send",- config: {- rateLimit: writeLimit- },- schema: {- operationId: "sendEmailMfaSetupCode",- response: {- 200: z.object({- message: z.string()- })- }- },- onRequest: verifyAuth([AuthMode.JWT], { requireOrg: false }),- handler: async (req) => {- await server.services.user.sendEmailMfaSetupCode({- userId: req.permission.id- });- return { message: "Successfully sent email verification code" };- }- });-- server.route({- method: "POST",- url: "/me/mfa/email/verify",- config: {- rateLimit: writeLimit- },- schema: {- operationId: "verifyEmailMfaSetupCode",- body: z.object({- code: z.string().trim()- }),- response: {- 200: z.object({- success: z.boolean()- })- }- },- onRequest: verifyAuth([AuthMode.JWT], { requireOrg: false }),- handler: async (req) => {- await server.services.user.verifyEmailMfaSetupCode({- userId: req.permission.id,- code: req.body.code- });- return { success: true };- }- });-// WebAuthn/Passkey Routesserver.route({method: "GET",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.tsindex e9c3d1508c..d74f705d98 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@@ -94,12 +94,14 @@ export const mfaRecoveryCodeServiceFactory = ({* ones. Returns the fresh codes so the caller can display them once. If no* pool exists yet it is created.*/- const rotateRecoveryCodes = async ({ userId, tx: externalTx }: TRotateRecoveryCodesDTO) => {- const user = await userDAL.findById(userId, externalTx);- if (!user?.isMfaEnabled) {- throw new BadRequestError({- message: "Cannot regenerate recovery codes: MFA is not enabled for this account"- });+ const rotateRecoveryCodes = async ({ userId, tx: externalTx, skipMfaEnabledCheck }: TRotateRecoveryCodesDTO) => {+ if (!skipMfaEnabledCheck) {+ const user = await userDAL.findById(userId, externalTx);+ if (!user?.isMfaEnabled) {+ throw new BadRequestError({+ message: "Cannot regenerate recovery codes: MFA is not enabled for this account"+ });+ }}const { recoveryCodes, encryptedRecoveryCodes } = generateEncryptedRecoveryCodes();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.tsindex f7f3c4914c..7811db2f53 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@@ -12,6 +12,7 @@ export type TVerifyAndConsumeRecoveryCodeDTO = {export type TRotateRecoveryCodesDTO = {userId: string;tx?: Knex;+ skipMfaEnabledCheck?: boolean;};export type TDeleteRecoveryCodesDTO = {diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex 5b1df742d0..7472033661 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -4,7 +4,6 @@ import { Knex } from "knex";import { AccessScope, OrganizationActionScope } from "@app/db/schemas";import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";-import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto";import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";@@ -50,7 +49,6 @@ type TUserServiceFactoryDep = {userAliasDAL: Pick<TUserAliasDALFactory, "findOne" | "find" | "updateById" | "delete">;totpConfigDAL: Pick<TTotpConfigDALFactory, "delete">;webAuthnCredentialDAL: Pick<TWebAuthnCredentialDALFactory, "delete">;- keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX" | "ttl">;mfaRecoveryCodeService: Pick<TMfaRecoveryCodeServiceFactory, "deleteRecoveryCodes" | "rotateRecoveryCodes">;};@@ -67,7 +65,6 @@ export const userServiceFactory = ({userAliasDAL,totpConfigDAL,webAuthnCredentialDAL,- keyStore,mfaRecoveryCodeService}: TUserServiceFactoryDep) => {const sendEmailVerificationCode = async (token: string) => {@@ -151,7 +148,8 @@ export const userServiceFactory = ({);if (isMfaEnabled === true && !wasMfaEnabled) {- await mfaRecoveryCodeService.rotateRecoveryCodes({ userId, tx });+ // MFA was just enabled in this transaction, so skip the redundant re-read.+ await mfaRecoveryCodeService.rotateRecoveryCodes({ userId, tx, skipMfaEnabledCheck: true });} else if (isMfaEnabled === false) {await mfaRecoveryCodeService.deleteRecoveryCodes({ userId, tx });await totpConfigDAL.delete({ userId }, tx);@@ -164,55 +162,6 @@ export const userServiceFactory = ({return updatedUser;};- // Sends a one-time code to the account email so the user can prove control of- // the inbox while adding email as a second factor from account settings.- const sendEmailMfaSetupCode = async ({ userId }: { userId: string }) => {- const user = await userDAL.findById(userId);- if (!user || !user.email) throw new BadRequestError({ message: "No email address is set on this account" });-- const cooldownKey = KeyStorePrefixes.MfaEmailSetupResendCooldown(userId);- const acquired = await keyStore.setItemWithExpiryNX(- cooldownKey,- KeyStoreTtls.MfaEmailSetupResendCooldownInSeconds,- "1"- );- if (!acquired) {- const remaining = await keyStore.ttl(cooldownKey);- throw new BadRequestError({- message: "Please wait before requesting another code",- details: { cooldownSeconds: Math.max(1, remaining) }- });- }-- const code = await tokenService.createTokenForUser({- type: TokenType.TOKEN_EMAIL_MFA,- userId- });-- await smtpService.sendMail({- template: SmtpTemplates.EmailMfa,- subjectLine: "Infisical MFA code",- recipients: [user.email],- substitutions: {- code- }- });- };-- // Verifies the email setup code so the caller can confirm the method works- // before enabling account MFA (which mints the recovery codes).- const verifyEmailMfaSetupCode = async ({ userId, code }: { userId: string; code: string }) => {- try {- await tokenService.validateTokenForUser({- type: TokenType.TOKEN_EMAIL_MFA,- userId,- code- });- } catch (error) {- throw new BadRequestError({ message: "Invalid verification code" });- }- };-const updateUserName = async (userId: string, firstName: string, lastName: string) => {const updatedUser = await userDAL.updateById(userId, {firstName,@@ -640,8 +589,6 @@ export const userServiceFactory = ({return {sendEmailVerificationCode,updateUserMfa,- sendEmailMfaSetupCode,- verifyEmailMfaSetupCode,updateUserName,updateAuthMethods,requestEmailChangeOTP,diff --git a/frontend/src/components/mfa/setup/VerifyStep.tsx b/frontend/src/components/mfa/setup/VerifyStep.tsxindex 67cad70b7c..e73db453b9 100644--- a/frontend/src/components/mfa/setup/VerifyStep.tsx+++ b/frontend/src/components/mfa/setup/VerifyStep.tsx@@ -1,19 +1,13 @@-import { useEffect, useRef, useState } from "react";-import { startRegistration } from "@simplewebauthn/browser";-import { FingerprintIcon } from "lucide-react";+import { useEffect, useState } from "react";+import { FingerprintIcon, MailIcon } from "lucide-react";import QRCode from "qrcode";import { createNotification } from "@app/components/notifications";import { ContentLoader } from "@app/components/v2";import { Button, Input } from "@app/components/v3";import { MfaMethod } from "@app/hooks/api/auth/types";-import {- useGetUserTotpRegistration,- useSendEmailMfaSetupCode,- useVerifyEmailMfaSetupCode,- useVerifyUserTotpRegistration-} from "@app/hooks/api/users";-import { useGenerateRegistrationOptions, useVerifyRegistration } from "@app/hooks/api/webauthn";+import { useGetUserTotpRegistration, useVerifyUserTotpRegistration } from "@app/hooks/api/users";+import { useRegisterPasskey } from "@app/hooks/api/webauthn";type Props = {method: MfaMethod;@@ -87,113 +81,41 @@ const TotpVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {);};-const RESEND_COOLDOWN_SECONDS = 60;-const EmailVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {- const { mutateAsync: sendCode } = useSendEmailMfaSetupCode();- const { mutateAsync: verifyCode, isPending: isVerifying } = useVerifyEmailMfaSetupCode();- const [code, setCode] = useState("");- const [cooldown, setCooldown] = useState(0);-- const hasSentRef = useRef(false);-- const sendAndStartCooldown = () => {- setCooldown(RESEND_COOLDOWN_SECONDS);- sendCode().catch((error: any) => {- const remaining = error?.response?.data?.details?.cooldownSeconds;- if (typeof remaining === "number") {- setCooldown(remaining);- return;- }- setCooldown(0);- createNotification({- text: error?.response?.data?.message || "Failed to send verification code",- type: "error"- });- });- };-- useEffect(() => {- if (hasSentRef.current) return;- hasSentRef.current = true;- sendAndStartCooldown();- // eslint-disable-next-line react-hooks/exhaustive-deps- }, []);+ const [isEnabling, setIsEnabling] = useState(false);- useEffect(() => {- if (cooldown <= 0) return undefined;- const timer = setTimeout(() => setCooldown((remaining) => remaining - 1), 1000);- return () => clearTimeout(timer);- }, [cooldown]);-- const handleVerify = async () => {+ const handleEnable = async () => {+ setIsEnabling(true);try {- await verifyCode({ code: code.trim() });- createNotification({ text: "Email verified", type: "success" });await onVerified();- } catch {- // The global mutation error handler surfaces the failure toast.+ } finally {+ setIsEnabling(false);}};return (<div className="flex flex-col gap-4">- <p className="text-sm text-muted">- We sent a one-time code to your account email. Enter it below to confirm.- </p>- <Input- value={code}- onChange={(e) => setCode(e.target.value.replace(/\D/g, "").slice(0, 6))}- placeholder="Enter 6-digit code"- maxLength={6}- />- <div className="flex items-center gap-3">- <Button- variant="org"- isPending={isVerifying}- isDisabled={code.trim().length !== 6}- onClick={handleVerify}- >- Verify code- </Button>- <Button variant="ghost" isDisabled={cooldown > 0} onClick={sendAndStartCooldown}>- {cooldown > 0 ? `Resend code in ${cooldown}s` : "Resend code"}- </Button>+ <div className="flex items-start gap-3 rounded-lg border border-border bg-container p-4">+ <MailIcon className="mt-0.5 text-muted" />+ <p className="text-sm text-muted">+ A one-time code will be sent to your account email each time you sign in. No setup is+ needed for this method.+ </p></div>+ <Button variant="org" isPending={isEnabling} onClick={handleEnable}>+ Enable email authentication+ </Button></div>);};const WebAuthnVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {- const { mutateAsync: generateOptions } = useGenerateRegistrationOptions();- const { mutateAsync: verifyRegistration, isPending } = useVerifyRegistration();+ const { registerPasskey, isRegistering } = useRegisterPasskey();const [name, setName] = useState("");const handleRegister = async () => {- try {- if (- !window.PublicKeyCredential ||- !window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable- ) {- createNotification({ text: "WebAuthn is not supported on this browser", type: "error" });- return;- }-- const options = await generateOptions();- const registrationResponse = await startRegistration({ optionsJSON: options });- await verifyRegistration({ registrationResponse, name: name.trim() || "Passkey" });-- createNotification({ text: "Passkey registered", type: "success" });+ if (await registerPasskey(name)) {await onVerified();- } catch (error: any) {- let text = "Failed to register passkey";- if (error.name === "NotAllowedError")- text = "Passkey registration was cancelled or timed out";- else if (error.name === "InvalidStateError")- text = "This passkey has already been registered";- else if (error?.response?.data?.message) text = error.response.data.message;- else if (error.message) text = error.message;- createNotification({ text, type: "error" });}};@@ -208,7 +130,7 @@ const WebAuthnVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) =>onChange={(e) => setName(e.target.value)}placeholder="Passkey name (optional)"/>- <Button variant="org" isPending={isPending} onClick={handleRegister}>+ <Button variant="org" isPending={isRegistering} onClick={handleRegister}><FingerprintIcon /> Register passkey</Button></div>diff --git a/frontend/src/components/mfa/setup/index.ts b/frontend/src/components/mfa/setup/index.tsindex 6ff5aa2905..3596372ec4 100644--- a/frontend/src/components/mfa/setup/index.ts+++ b/frontend/src/components/mfa/setup/index.ts@@ -1,6 +1,5 @@export { MethodStep } from "./MethodStep";export { RecoveryCodesView } from "./RecoveryCodesView";export type { MfaMethodOption, WizardStep } from "./types";-export { MFA_METHOD_LABELS as METHOD_LABELS, MFA_METHOD_LABELS, MFA_METHOD_OPTIONS } from "./types";-export { WIZARD_STEPS } from "./types";+export { MFA_METHOD_ICONS, MFA_METHOD_LABELS, MFA_METHOD_OPTIONS, WIZARD_STEPS } from "./types";export { VerifyStep } from "./VerifyStep";diff --git a/frontend/src/components/mfa/setup/types.ts b/frontend/src/components/mfa/setup/types.tsindex 2b2d223197..8e2137d3fd 100644--- a/frontend/src/components/mfa/setup/types.ts+++ b/frontend/src/components/mfa/setup/types.ts@@ -30,11 +30,15 @@ export const MFA_METHOD_OPTIONS: MfaMethodOption[] = [}];-export const MFA_METHOD_LABELS: Record<MfaMethod, string> = {- [MfaMethod.TOTP]: "Authenticator app",- [MfaMethod.EMAIL]: "Email",- [MfaMethod.WEBAUTHN]: "Passkey"-};+export const MFA_METHOD_LABELS = MFA_METHOD_OPTIONS.reduce(+ (acc, option) => ({ ...acc, [option.value]: option.label }),+ {} as Record<MfaMethod, string>+);++export const MFA_METHOD_ICONS = MFA_METHOD_OPTIONS.reduce(+ (acc, option) => ({ ...acc, [option.value]: option.icon }),+ {} as Record<MfaMethod, LucideIcon>+);export type WizardStep = {key: "method" | "verify" | "recovery";diff --git a/frontend/src/hooks/api/users/index.tsx b/frontend/src/hooks/api/users/index.tsxindex 3bca7df88e..091df51856 100644--- a/frontend/src/hooks/api/users/index.tsx+++ b/frontend/src/hooks/api/users/index.tsx@@ -5,11 +5,9 @@ export {useRequestEmailChangeOTP,useRevokeMySessionById,useRotateMfaRecoveryCodes,- useSendEmailMfaSetupCode,useSendEmailVerificationCode,useUpdateUserEmail,useVerifyCurrentEmailOTP,- useVerifyEmailMfaSetupCode,useVerifyUserTotpRegistration} from "./mutation";export {diff --git a/frontend/src/hooks/api/users/mutation.tsx b/frontend/src/hooks/api/users/mutation.tsxindex cb9e0b0f3d..5f44067b6c 100644--- a/frontend/src/hooks/api/users/mutation.tsx+++ b/frontend/src/hooks/api/users/mutation.tsx@@ -82,27 +82,6 @@ export const useVerifyUserTotpRegistration = () => {});};-export const useSendEmailMfaSetupCode = () => {- return useMutation<{ message: string }, unknown, void>({- mutationFn: async () => {- const { data } = await apiRequest.post<{ message: string }>("/api/v1/user/me/mfa/email/send");- return data;- }- });-};--export const useVerifyEmailMfaSetupCode = () => {- return useMutation<{ success: boolean }, unknown, { code: string }>({- mutationFn: async ({ code }: { code: string }) => {- const { data } = await apiRequest.post<{ success: boolean }>(- "/api/v1/user/me/mfa/email/verify",- { code }- );- return data;- }- });-};-export const useDeleteUserTotpConfiguration = () => {const queryClient = useQueryClient();return useMutation({diff --git a/frontend/src/hooks/api/webauthn/index.tsx b/frontend/src/hooks/api/webauthn/index.tsxindex 4bcb5b5fa9..df0f1e19b7 100644--- a/frontend/src/hooks/api/webauthn/index.tsx+++ b/frontend/src/hooks/api/webauthn/index.tsx@@ -16,3 +16,4 @@ export type {TVerifyRegistrationDTO,TWebAuthnCredential} from "./types";+export { useRegisterPasskey } from "./useRegisterPasskey";diff --git a/frontend/src/hooks/api/webauthn/useRegisterPasskey.tsx b/frontend/src/hooks/api/webauthn/useRegisterPasskey.tsxnew file mode 100644index 0000000000..286a681a99--- /dev/null+++ b/frontend/src/hooks/api/webauthn/useRegisterPasskey.tsx@@ -0,0 +1,53 @@+import { useState } from "react";+import { startRegistration } from "@simplewebauthn/browser";++import { createNotification } from "@app/components/notifications";++import { useGenerateRegistrationOptions, useVerifyRegistration } from "./mutations";++const DEFAULT_PASSKEY_NAME = "Passkey";++// Shared passkey registration flow (browser support guard -> options -> prompt ->+// verify) with consistent success/error notifications. Returns true on success so+// callers can chain follow-up work (e.g. advancing a wizard step).+export const useRegisterPasskey = () => {+ const { mutateAsync: generateOptions } = useGenerateRegistrationOptions();+ const { mutateAsync: verifyRegistration } = useVerifyRegistration();+ const [isRegistering, setIsRegistering] = useState(false);++ const registerPasskey = async (name?: string): Promise<boolean> => {+ if (+ !window.PublicKeyCredential ||+ !window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable+ ) {+ createNotification({ text: "WebAuthn is not supported on this browser", type: "error" });+ return false;+ }++ setIsRegistering(true);+ try {+ const options = await generateOptions();+ const registrationResponse = await startRegistration({ optionsJSON: options });+ await verifyRegistration({+ registrationResponse,+ name: name?.trim() || DEFAULT_PASSKEY_NAME+ });+ createNotification({ text: "Passkey registered", type: "success" });+ return true;+ } catch (error: any) {+ let text = "Failed to register passkey";+ if (error.name === "NotAllowedError")+ text = "Passkey registration was cancelled or timed out";+ else if (error.name === "InvalidStateError")+ text = "This passkey has already been registered";+ else if (error?.response?.data?.message) text = error.response.data.message;+ else if (error.message) text = error.message;+ createNotification({ text, type: "error" });+ return false;+ } finally {+ setIsRegistering(false);+ }+ };++ return { registerPasskey, isRegistering };+};diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsxindex 1f5b6b00c2..1b45a93cf8 100644--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx@@ -1,14 +1,8 @@import { useState } from "react";import { useQueryClient } from "@tanstack/react-query";-import {- CircleAlertIcon,- FingerprintIcon,- MailIcon,- PowerIcon,- ShieldCheckIcon,- SmartphoneIcon-} from "lucide-react";+import { CircleAlertIcon, PowerIcon, ShieldCheckIcon } from "lucide-react";+import { MFA_METHOD_ICONS, MFA_METHOD_LABELS } from "@app/components/mfa/setup";import { createNotification } from "@app/components/notifications";import { ContentLoader } from "@app/components/v2";import {@@ -40,18 +34,6 @@ import { RecoveryOptionsCard } from "./RecoveryOptionsCard";const LEARN_MORE_URL = "https://infisical.com/docs/documentation/platform/mfa";-const PREFERRED_METHOD_ICONS: Record<MfaMethod, typeof MailIcon> = {- [MfaMethod.TOTP]: SmartphoneIcon,- [MfaMethod.EMAIL]: MailIcon,- [MfaMethod.WEBAUTHN]: FingerprintIcon-};--const PREFERRED_METHOD_LABELS: Record<MfaMethod, string> = {- [MfaMethod.TOTP]: "Authenticator app",- [MfaMethod.EMAIL]: "Email",- [MfaMethod.WEBAUTHN]: "Passkey"-};-export const MFASection = () => {const { data: user, isPending } = useGetUser();const { mutateAsync: updateUserMfa, isPending: isUpdating } = useUpdateUserMfa();@@ -178,12 +160,12 @@ export const MFASection = () => {</SelectTrigger><SelectContent>{availableMethods.map((method) => {- const Icon = PREFERRED_METHOD_ICONS[method];+ const Icon = MFA_METHOD_ICONS[method];return (<SelectItem key={method} value={method}><span className="flex items-center gap-2"><Icon />- {PREFERRED_METHOD_LABELS[method]}+ {MFA_METHOD_LABELS[method]}</span></SelectItem>);diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsxindex ec0d501487..5a919c3787 100644--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx@@ -1,7 +1,8 @@import { useState } from "react";import { useQueryClient } from "@tanstack/react-query";-import { FingerprintIcon, LucideIcon, MailIcon, SmartphoneIcon } from "lucide-react";+import { LucideIcon } from "lucide-react";+import { MFA_METHOD_ICONS, MFA_METHOD_LABELS } from "@app/components/mfa/setup";import { createNotification } from "@app/components/notifications";import {AlertDialog,@@ -78,16 +79,16 @@ export const MfaMethodsCard = () => {<h3 className="mb-2 text-sm font-medium text-foreground">Two-factor methods</h3><div className="divide-y divide-border"><MethodRow- icon={MailIcon}- title="Email"+ icon={MFA_METHOD_ICONS[MfaMethod.EMAIL]}+ title={MFA_METHOD_LABELS[MfaMethod.EMAIL]}description="Receive one-time codes at your account email address to complete sign-in."badge={<Badge variant="success">Configured</Badge>}action={null}/><MethodRow- icon={SmartphoneIcon}- title="Authenticator app"+ icon={MFA_METHOD_ICONS[MfaMethod.TOTP]}+ title={MFA_METHOD_LABELS[MfaMethod.TOTP]}description="Use a TOTP authenticator app to get one-time codes when prompted at sign-in."badge={isTotpConfigured ? (@@ -110,7 +111,7 @@ export const MfaMethodsCard = () => {/><MethodRow- icon={FingerprintIcon}+ icon={MFA_METHOD_ICONS[MfaMethod.WEBAUTHN]}title="Passkeys"description="Passkeys use Face ID, Touch ID, a security key, or your device to sign in."badge={diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/PasskeyManagerDialog.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/PasskeyManagerDialog.tsxindex e5e22d71cb..dd918fac62 100644--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/PasskeyManagerDialog.tsx+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/PasskeyManagerDialog.tsx@@ -1,5 +1,4 @@import { useState } from "react";-import { startRegistration } from "@simplewebauthn/browser";import { FingerprintIcon, PlusIcon, TrashIcon } from "lucide-react";import { createNotification } from "@app/components/notifications";@@ -15,9 +14,8 @@ import {} from "@app/components/v3";import {useDeleteWebAuthnCredential,- useGenerateRegistrationOptions,useGetWebAuthnCredentials,- useVerifyRegistration+ useRegisterPasskey} from "@app/hooks/api/webauthn";type Props = {@@ -27,35 +25,14 @@ type Props = {export const PasskeyManagerDialog = ({ isOpen, onOpenChange }: Props) => {const { data: credentials = [], isPending } = useGetWebAuthnCredentials();- const { mutateAsync: generateOptions } = useGenerateRegistrationOptions();- const { mutateAsync: verifyRegistration, isPending: isRegistering } = useVerifyRegistration();+ const { registerPasskey, isRegistering } = useRegisterPasskey();const { mutateAsync: deleteCredential } = useDeleteWebAuthnCredential();const [name, setName] = useState("");const handleAdd = async () => {- try {- if (- !window.PublicKeyCredential ||- !window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable- ) {- createNotification({ text: "WebAuthn is not supported on this browser", type: "error" });- return;- }- const options = await generateOptions();- const registrationResponse = await startRegistration({ optionsJSON: options });- await verifyRegistration({ registrationResponse, name: name.trim() || "Passkey" });+ if (await registerPasskey(name)) {setName("");- createNotification({ text: "Passkey registered", type: "success" });- } catch (error: any) {- let text = "Failed to register passkey";- if (error.name === "NotAllowedError")- text = "Passkey registration was cancelled or timed out";- else if (error.name === "InvalidStateError")- text = "This passkey has already been registered";- else if (error?.response?.data?.message) text = error.response.data.message;- else if (error.message) text = error.message;- createNotification({ text, type: "error" });}};