fix(2FA): use serializable transaction for failed attempts recording

This commit is contained in:
Rudy B. committed 2026-04-25 17:28:29 +02:00
1 parent df913fd77f
commit 5c5d1c3524
4 files changed
+38 -13

No files matched your search

+2 -1
View File
@@ -88,10 +88,11 @@ export async function POST(request: Request) {
// Verify TOTP
const secret = decryptSecret(twoFactor.secret);
if (!(await verifyTotp(token, secret))) {
await recordFailedAttempt(userId);
const { lockedUntil } = await recordFailedAttempt(userId);
return badRequest({
code: 'two-factor-error-invalid-code',
message: 'Invalid verification code',
...(lockedUntil && { lockedUntil }),
});
}
+2 -1
View File
@@ -48,10 +48,11 @@ export async function POST(request: Request) {
// Verify TOTP
const secret = decryptSecret(twoFactor.secret);
if (!(await verifyTotp(token, secret))) {
await recordFailedAttempt(userId);
const { lockedUntil } = await recordFailedAttempt(userId);
return badRequest({
code: 'two-factor-error-invalid-code',
message: 'Invalid verification code',
...(lockedUntil && { lockedUntil }),
});
}
+4 -2
View File
@@ -73,10 +73,11 @@ export async function POST(request: Request) {
const matchIndex = await verifyBackupCode(body.backupCode, hashes);
if (matchIndex === null) {
await recordFailedAttempt(userId);
const { lockedUntil } = await recordFailedAttempt(userId);
return badRequest({
code: 'two-factor-error-invalid-backup-code',
message: 'Invalid backup code',
...(lockedUntil && { lockedUntil }),
});
}
@@ -95,10 +96,11 @@ export async function POST(request: Request) {
const decryptedSecret = decryptSecret(twoFactor.secret);
if (!(await verifyTotp(token, decryptedSecret))) {
await recordFailedAttempt(userId);
const { lockedUntil } = await recordFailedAttempt(userId);
return badRequest({
code: 'two-factor-error-invalid-code',
message: 'Invalid verification code',
...(lockedUntil && { lockedUntil }),
});
}