From c4cd04eb95d7ce29862f5b78f9a253c8a28ca5f7 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Thu, 13 Jun 2024 23:50:32 +0200 Subject: [PATCH] feat: :sparkles: pass session state to downstream contexts --- routes/_middleware.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/_middleware.ts b/routes/_middleware.ts index 1e31fcf..903f5b7 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -3,6 +3,9 @@ import { getCookies, setCookie } from '@std/http/cookie' import { SessionStore } from '../src/session/mod.ts' export async function handler(request: Request, ctx: FreshContext) { + // Update fresh context state with session + ctx.state = { ...ctx.state, session: SessionStore.getFromRequest(request) } + // Allow service worker to serve root scope const response = await ctx.next() const url = new URL(request.url) @@ -24,6 +27,7 @@ export async function handler(request: Request, ctx: FreshContext) { // Create new session const session = SessionStore.createSession() + ctx.state = { ...ctx.state, session } // Set session cookie setCookie(response.headers, {