feat: pass session state to downstream contexts

This commit is contained in:
Julien Oculi 2024-06-13 23:50:32 +02:00
parent ca482e8956
commit c4cd04eb95

View file

@ -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, {