import { ConfigStore } from '../../../config/store.ts' export type CachedSession = { token: string /** ISO timestamp when the token expires (2 days from issue). */ expiresAt: string /** Email of the user who authorized (if available). */ email?: string } /** Persist the auth token to the `session` section of the unified config. */ export function writeSession(session: CachedSession) { new ConfigStore().write({ session }) } /** * Read the cached session, returning it only if the token is still * valid (not yet expired). Returns undefined on any error. */ export function readSession(): CachedSession | undefined { const s = new ConfigStore().read()?.session if(!s?.token || !s.expiresAt) { return undefined } if(new Date(s.expiresAt) <= new Date()) { return undefined // expired } return s }