From b032fe21618144b84dda8b98e1d812480c2d10a9 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Thu, 13 Jun 2024 14:42:39 +0200 Subject: [PATCH] fix: :bug: patch cookie clear process --- routes/_middleware.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routes/_middleware.ts b/routes/_middleware.ts index 9e9dcfe..f346284 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -1,5 +1,5 @@ import { FreshContext } from '$fresh/server.ts' -import { deleteCookie, getCookies, setCookie } from '@std/http/cookie' +import { getCookies, setCookie } from '@std/http/cookie' import { SessionStore } from '../src/session/mod.ts' const instanceToken = crypto.randomUUID() // Instance uuid to reset perform cookie reset on server restart @@ -17,7 +17,11 @@ export async function handler(request: Request, ctx: FreshContext) { // Clear outdated cookies if (cookies['_INSTANCE'] !== instanceToken) { for (const cookie in cookies) { - deleteCookie(request.headers, cookie) + setCookie(response.headers, { + name: cookie, + value: '', + expires: 0, + }) } setCookie(response.headers, { name: '_INSTANCE', @@ -25,11 +29,12 @@ export async function handler(request: Request, ctx: FreshContext) { httpOnly: true, sameSite: 'Strict', secure: true, + expires: 1000 * 2 ** 38, // Never expire }) } // Start session - if (cookies['_SESSION'] === undefined) { + if (cookies['_SESSION'] === undefined || cookies['_SESSION'] === '') { const session = SessionStore.createSession() // Set session cookie