Skip to content

Commit ed16ca7

Browse files
committed
Don't update code test attempts when there are no codes
This caused issues, because you can't IN an empty list.
1 parent 092bf37 commit ed16ca7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

api/src/user-data-facade.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,20 @@ export async function loginWithPasswordlessCode(email: string, code: string, use
228228
const matchingCode = !overusedCode && !!existingCodes.find(c => c.value === code);
229229

230230
if (!matchingCode || overusedCode) {
231-
// Increment attempts for all existing codes for this email:
232-
await db.updateTable('login_tokens')
233-
.set({
234-
attempts: sql`attempts + 1`
235-
})
236-
.where('email', '=', email)
237-
.where('id', 'in', existingCodes.map(c => c.id))
238-
.execute();
231+
if (existingCodes.length) {
232+
// Increment attempts for all existing codes for this email:
233+
await db.updateTable('login_tokens')
234+
.set({
235+
attempts: sql`attempts + 1`
236+
})
237+
.where('email', '=', email)
238+
.where('id', 'in', existingCodes.map(c => c.id))
239+
.execute();
240+
}
239241

240242
if (overusedCode) {
241243
throw new StatusError(429, 'Too many login attempts - please try again later');
242-
}
243-
244-
if (!matchingCode) {
244+
} else {
245245
throw new StatusError(403, 'Invalid or expired login code');
246246
}
247247
}

0 commit comments

Comments
 (0)