From fd72fd85f88a6c672e305ea14cc26af21fbb8dd4 Mon Sep 17 00:00:00 2001 From: Janpeter Visser Date: Fri, 24 Apr 2026 22:08:27 +0200 Subject: [PATCH] Document iron-session pattern and usage Add documentation for iron-session pattern including session options and usage in server actions. --- patterns/iron-session.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/patterns/iron-session.md b/patterns/iron-session.md index 41da259..f979904 100644 --- a/patterns/iron-session.md +++ b/patterns/iron-session.md @@ -1,3 +1,8 @@ +# Patroon: iron-session + +## lib/session.ts + +```ts import { SessionOptions } from 'iron-session' export interface SessionData { @@ -14,3 +19,16 @@ export const sessionOptions: SessionOptions = { sameSite: 'lax', }, } +``` + +## Gebruik in Server Action of Route Handler + +```ts +import { getIronSession } from 'iron-session' +import { cookies } from 'next/headers' +import { SessionData, sessionOptions } from '@/lib/session' + +const session = await getIronSession(await cookies(), sessionOptions) +if (!session.userId) redirect('/login') +if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } +```