wrap rotateSessionId transaction in try/catch, return null on failure

This commit is contained in:
null 2026-06-03 20:37:12 -05:00
parent 2550034996
commit 4b86898bc7
1 changed files with 9 additions and 5 deletions

View File

@ -128,11 +128,15 @@ function rotateSessionId(oldSessionId, userId) {
.toISOString().slice(0, 19).replace('T', ' '); .toISOString().slice(0, 19).replace('T', ' ');
// Delete old session and create new one atomically // Delete old session and create new one atomically
try {
db.transaction(() => { db.transaction(() => {
db.prepare('DELETE FROM sessions WHERE id = ?').run(oldSessionId); db.prepare('DELETE FROM sessions WHERE id = ?').run(oldSessionId);
db.prepare('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)') db.prepare('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)')
.run(newSessionId, userId, expiresAt); .run(newSessionId, userId, expiresAt);
})(); })();
} catch {
return null;
}
return newSessionId; return newSessionId;
} }