mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
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.
14 lines
554 B
TypeScript
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
|
|
}
|