fix(2FA): error when trying to setup an already activated 2FA

This commit is contained in:
Rudy B. committed 2026-04-25 20:05:50 +02:00
1 parent 3e165a8c6f
commit 4b15f2ad7c
4 files changed
+12

No files matched your search

+9
View File
@@ -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);