feat: ✨ pass session state to downstream contexts
This commit is contained in:
parent
ca482e8956
commit
c4cd04eb95
|
@ -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, {
|
||||
|
|
Loading…
Reference in a new issue