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', ' ');
// Delete old session and create new one atomically
db.transaction(() => {
db.prepare('DELETE FROM sessions WHERE id = ?').run(oldSessionId);
db.prepare('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)')
.run(newSessionId, userId, expiresAt);
})();
try {
db.transaction(() => {
db.prepare('DELETE FROM sessions WHERE id = ?').run(oldSessionId);
db.prepare('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)')
.run(newSessionId, userId, expiresAt);
})();
} catch {
return null;
}
return newSessionId;
}