Files
opencode-manager/backend/src/db/auth-sessions.ts
T
Chris Scott a769d3fd34 fix(notifications): reject push registrations from revoked sessions
POST /subscribe re-checks the registering auth session inside the same synchronous transaction as the upsert, so a request accepted before a logout cannot restore a revoked session_id over a newer registration. A stale request gets 401, which the session sync already tolerates.
2026-10-24 19:26:21 -04:00

14 lines
554 B
TypeScript

import type { Database } from 'bun:sqlite'
/** Reports whether a Better Auth session row still exists and has not expired. */
export function isAuthSessionActive(db: Database, sessionId: string, now: number = Date.now()): boolean {
const row = db
.prepare('SELECT expiresAt FROM "session" WHERE id = ?')
.get(sessionId) as { expiresAt: string | number } | null
if (!row) return false
const expiresAt = typeof row.expiresAt === 'number' ? row.expiresAt : Date.parse(row.expiresAt)
return Number.isFinite(expiresAt) && expiresAt > now
}