import fs from 'fs/promises'; import path from 'path'; const SESSION_DIR = path.join(process.cwd(), 'session_cache'); export async function saveSession(sessionId: string, userId: string) { await fs.mkdir(SESSION_DIR, { recursive: true }); await fs.writeFile( path.join(SESSION_DIR, `${sessionId}.json`), JSON.stringify({ userId }), ); } export async function loadSession(sessionId: string): Promise { try { const file = await fs.readFile( path.join(SESSION_DIR, `${sessionId}.json`), 'utf-8' ); return JSON.parse(file).userId; } catch { return null; } } export async function clearSessionFile(sessionId: string) { try { await fs.unlink(path.join(SESSION_DIR, `${sessionId}.json`)); } catch { } }