Document iron-session pattern and usage

Add documentation for iron-session pattern including session options and usage in server actions.
This commit is contained in:
Janpeter Visser 2026-04-24 22:08:27 +02:00 committed by GitHub
parent 08e0dd22f0
commit fd72fd85f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<SessionData>(await cookies(), sessionOptions)
if (!session.userId) redirect('/login')
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
```