UNPKG

@athenox/talos

Version:

Talos: a backend you describe instead of write. Declare a schema, write the rules in plain language, map URLs to sentences; a small built-in model turns them into query plans.

28 lines (27 loc) • 981 B
import { randomUUID } from 'node:crypto'; import { getCookie, setCookie } from 'h3'; /** * Session plumbing, owned by the runtime rather than by any app. * * This is the half of "auth" a prompt cannot express: issuing a cookie and * holding server-side state. It carries no policy — who may do what is declared * in the app's `roles` and enforced by `authorise`. */ const COOKIE = 'talos_sid'; // ponytail: in-process map. Swap for redis/a table when you need more than one node. const store = new Map(); export function useSession(event) { let sid = getCookie(event, COOKIE); if (!sid || !store.has(sid)) { sid = randomUUID(); store.set(sid, {}); setCookie(event, COOKIE, sid, { httpOnly: true, sameSite: 'lax', path: '/', maxAge: 86400 }); } const data = store.get(sid); return { sid, get: key => data[key], set: (key, value) => { data[key] = value; }, clear: () => store.set(sid, {}), }; }