fix: usa strftime('now') en SQL y simplifica canje de token

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
webui
brobert 2 weeks ago
parent 5616ee8395
commit cdfd16f2fa

@ -16,20 +16,19 @@ export const GET: RequestHandler = async (event) => {
// Hash del token (no loguear el valor en claro)
const tokenHash = await sha256Hex(token);
const nowIso = toIsoSql(new Date());
const db = await getDb();
// Intentar canjear el token: marcarlo como usado si está vigente y no usado
// Intentar canjear el token: marcarlo como usado si está vigente y no usado (usar tiempo de SQLite)
const res = db
.prepare(
`UPDATE web_tokens
SET used_at = ?
SET used_at = strftime('%Y-%m-%d %H:%M:%f','now')
WHERE token_hash = ?
AND used_at IS NULL
AND expires_at > ?`
AND expires_at > strftime('%Y-%m-%d %H:%M:%f','now')`
)
.run(nowIso, tokenHash, nowIso);
.run(tokenHash);
const changes = Number(res?.changes || 0);
if (changes < 1) {

Loading…
Cancel
Save