fix(2FA): use serializable transaction for failed attempts recording
This commit is contained in:
1 parent
df913fd77f
commit
5c5d1c3524
4 files changed
+38
-13
No files matched your search
@@ -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 }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user