clearSession

tcmts.server.clearSession · #ben5n2ro · term · runs on the server

uses #tcm/host (database)

End the caller's session.

import { deleteCookie, requestNow, SESSION_COOKIE, sessionOf } from "#codebase/tcmts/server";
import { database } from "#tcm/host";

export function clearSession(): void {
  const c = requestNow("clearSession()");
  const old = sessionOf(c);
  if (old) database("sessions").prepare("DELETE FROM sessions WHERE id = ?").run(old.id);
  delete c.request.cookies[SESSION_COOKIE];
  deleteCookie(SESSION_COOKIE);
}

uses

used by