Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
fix(2FA): error when trying to setup an already activated 2FA
Rudy B.4b15f2ad7c9c
diff --git a/public/intl/messages/en-US.json b/public/intl/messages/en-US.jsonindex bc51979b9..980c6c02e 100644--- a/public/intl/messages/en-US.json+++ b/public/intl/messages/en-US.json@@ -485,6 +485,7 @@"two-factor-error-too-many-attempts": "Too many failed attempts. Your account is temporarily locked.","two-factor-error-disable-not-allowed": "Two-factor authentication is required and cannot be disabled.","two-factor-error-incorrect-password": "Incorrect password.",+ "two-factor-error-already-enabled": "Two-factor authentication is already enabled.","two-factor-error-not-enabled": "Two-factor authentication is not enabled.","two-factor-error-no-pending-setup": "No pending two-factor authentication setup found.","two-factor-locked-message": "Too many failed attempts. Try again at {time}.",diff --git a/public/intl/messages/fr-FR.json b/public/intl/messages/fr-FR.jsonindex 51860286f..b6810ad56 100644--- a/public/intl/messages/fr-FR.json+++ b/public/intl/messages/fr-FR.json@@ -483,6 +483,7 @@"two-factor-error-too-many-attempts": "Trop de tentatives infructueuses. Votre compte est temporairement verrouillé.","two-factor-error-disable-not-allowed": "L’authentification à deux facteurs est obligatoire et ne peut pas être désactivée.","two-factor-error-incorrect-password": "Mot de passe incorrect.",+ "two-factor-error-already-enabled": "L’authentification à deux facteurs est déjà activée.","two-factor-error-not-enabled": "L’authentification à deux facteurs n’est pas activée.","two-factor-error-no-pending-setup": "Aucune configuration d’authentification à deux facteurs en attente n’a été trouvée.","two-factor-locked-message": "Trop de tentatives infructueuses. Réessayez à {time}.",diff --git a/src/app/api/2fa/setup/initiate/route.ts b/src/app/api/2fa/setup/initiate/route.tsindex 43a83f191..00a071674 100644--- a/src/app/api/2fa/setup/initiate/route.ts+++ b/src/app/api/2fa/setup/initiate/route.ts@@ -23,6 +23,15 @@ export async function POST(request: Request) {return badRequest({ message: 'User not found' });}+ const existing = await prisma.client.twoFactorAuth.findUnique({ where: { userId } });++ if (existing?.isEnabled) {+ return badRequest({+ code: 'two-factor-error-already-enabled',+ message: '2FA is already enabled',+ });+ }+const secret = generateTotpSecret();const encryptedSecret = encryptSecret(secret);const otpAuthUri = generateOtpAuthUri(secret, user.username);diff --git a/src/components/messages.ts b/src/components/messages.tsindex b62590b63..4d6b332d6 100644--- a/src/components/messages.ts+++ b/src/components/messages.ts@@ -487,6 +487,7 @@ export const messages: Record<string, string> = {twoFactorErrorTooManyAttempts: 'message.two-factor-error-too-many-attempts',twoFactorErrorDisableNotAllowed: 'message.two-factor-error-disable-not-allowed',twoFactorErrorIncorrectPassword: 'message.two-factor-error-incorrect-password',+ twoFactorErrorAlreadyEnabled: 'message.two-factor-error-already-enabled',twoFactorErrorNotEnabled: 'message.two-factor-error-not-enabled',twoFactorErrorNoPendingSetup: 'message.two-factor-error-no-pending-setup',};