From 1a85690bddb259c3fc71a22302038c07a952fe2c Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 2 Oct 2025 11:15:16 -0700 Subject: [PATCH] Feat: Clear auth cookies on logout --- functions/api/logout.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/functions/api/logout.js b/functions/api/logout.js index e812e0f..540739b 100644 --- a/functions/api/logout.js +++ b/functions/api/logout.js @@ -1,7 +1,8 @@ -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': '/' } }); +export async function onRequest() { + const opts = `Domain=.speech.capital; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT`; + const headers = new Headers(); + headers.append('Set-Cookie', `auth_user=; ${opts}`); + headers.append('Set-Cookie', `auth_hash=; ${opts}`); + headers.append('Location', '/'); + return new Response(null, { status: 302, headers }); }