Feat: Logout endpoint to clear session

This commit is contained in:
2025-10-02 11:07:49 -07:00
parent 03e44dee78
commit 9c94f66753

7
functions/api/logout.js Normal file
View File

@@ -0,0 +1,7 @@
export async function onRequest({ request, env }) {
const sid = (request.headers.get('Cookie')||'').match(/session_id=([^;]+)/)?.[1];
if (sid) await env.D1_SPCHCAP.prepare('DELETE FROM sessions WHERE id = ?').bind(sid).run();
const cookie = `session_id=; Domain=.speech.capital; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT`;
return new Response(null, { status: 302, headers: { 'Set-Cookie': cookie, 'Location': '/' } });
}