fix(2FA): error when trying to setup an already activated 2FA
This commit is contained in:
1 parent
3e165a8c6f
commit
4b15f2ad7c
4 files changed
+12
No files matched your search
@@ -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}.",
|
||||
|
||||
@@ -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}.",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
Reference in new issue
Block a user