The Basics
Session
Introduction
Browser sessions in JCC Express MVC build on express-session and connect-flash, registered in the framework’s global middleware stack. After those run, each request gets:
req.session— the Express session object (plain record you can read and assign).req.flash(...)— flash messaging API fromconnect-flash(messages cleared after they are read on the next request pattern).req.jccSession— a session bridge that mirrors the same store:get/put/flash/getFlash/all/forget/flush, plussave,regenerate, andgetId.
The global helper session() returns request()?.jccSession when the per-request container binding is active (same window as request() / response() — see Request and Routing).
HTTP handlers normally use req.session and req.jccSession.
Configuration
Session middleware uses express-session with options such as secret: process.env.SESSION_SECRET || "your_secret", resave, saveUninitialized, and cookie secure flags. Harden this in production: set SESSION_SECRET in .env, enable secure cookies behind HTTPS, and tune sameSite as needed.
Configure drivers, lifetime, and cookie options in app/Config/session.ts when you need file, database, or Redis session storage.
Reading and writing session data
Via req.session
Via req.jccSession (recommended JCC style)
Via session() (inside a request, after middleware)
flush() on jccSession removes all keys except the session cookie metadata.
Persisting and rotating the session
await req.jccSession?.save()— Callsreq.session.save()when available so the store persists before you finish the response (useful before a redirect after login).await req.jccSession?.regenerate()— Callsreq.session.regenerate()when available; use after authentication to reduce fixation risk.getId()— Current session id string when exposed by Express (sessionIDon the request).
If req.session is undefined (middleware mis-ordered or disabled), jccSession will not be useful—ensure the session stack runs before your routes.
Flash messages
connect-flash adds req.flash. Typical usage:
jccSession.flash / getFlash delegate to req.flash so they stay aligned with res.with().
In Blade, flash-backed res.locals for validation and old input are available on the next render; see Request and Response.
CSRF and session
The csrf() middleware stores the CSRF token in the session (see CSRF-protection.md). Session middleware must run before csrf() in the pipeline so req.session exists when the token is created.
Summary
- Sessions rely on
express-session+connect-flash;req.jccSessionis the typed bridge forget/put/flash/all/flush/save/regenerate. - Use
session()for the same API from globals during a request. - Flash:
req.flashorjccSession.flash/getFlash;res.withintegrates with flash for UI messages. - Configure secrets and cookies for production; call
save()/regenerate()when your auth flow requires it.