fix: Prisma $queryRaw MySQL type coercion for BigInt and Boolean

$queryRaw on MySQL returns BigInt for integer columns and 0/1 for booleans.
Passing these raw values back to Prisma client methods causes validation errors:
- Expected Int, provided BigInt
- Expected Boolean, provided Int

Fixed in auth refresh, TOTP login, and TOTP backup code flows by wrapping
storedToken.id, storedToken.user_id with Number() and remember_me with Boolean().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-04-24 11:18:38 +02:00
parent 8c278be941
commit a9bc82fac5
3 changed files with 23 additions and 8 deletions

View File

@@ -126,10 +126,14 @@ export default async function authRoutes(
return { error: "Neplatný nebo expirovaný login token", status: 401 };
}
await tx.totp_login_tokens.delete({ where: { id: storedToken.id } });
// $queryRaw on MySQL may return BigInt for integer columns
const storedTokenId = Number(storedToken.id);
const storedUserId = Number(storedToken.user_id);
await tx.totp_login_tokens.delete({ where: { id: storedTokenId } });
const user = await tx.users.findUnique({
where: { id: storedToken.user_id },
where: { id: storedUserId },
include: { roles: true },
});