v9.0.0
pnpm add iron-sessionNeeds Node 22.13+ and is ESM-only (require() works on Node 22.13+). Stuck on older Node, or need CommonJS? Stay on iron-session@8.
How to upgrade
Most apps change two things. Both are things v8 got wrong quietly.
- session.lastSeen = new Date(); // v8 sealed this as a string
+ session.lastSeen = Date.now();
- const userId = session.user.id; // empty on a first visit
+ const userId = session.user?.id;Nothing else is required:
getIronSession(req, res, options)andgetIronSession(await cookies(), options)both still work. Delete anyas anyyou had onawait cookies().- v9 reads v8 cookies and v8 reads v9 cookies, so a deploy rolls back without signing everyone out.
- Users on pre-v8 cookies (iron-session 6 and older) sign in once more. That format picked its shape from a marker outside the signature, so an attacker could flip it.
Full guide: MIGRATION.md.
What's new
- Sessions work in Next.js Proxy (middleware), via
nextProxyCookies - Sessions can be bigger than 4KB, with
chunk: true getIronSession(await cookies(), options)typechecks- Four bugs that lost sessions or logouts without an error are fixed
onUnsealErrortells you why a cookie was rejected- TypeScript catches reads of a session that may not exist
- Tested in Chromium, Firefox and WebKit, plus Node 22/24/26, Bun and Deno
The detail behind each of these is in the v9.0.0-beta.0 notes, and beta.1 softened four guards that turned out to break working logout handlers.
v9 runs in production on TurnShift, which is how the logout bug in beta.0 was found: existing sessions, magic links generated by AWS Lambda, session reads and writes, and logout were all verified against a real app before this release.