Encrypted cookie-based session middleware for Koa, built on top of koa-session. Current stable version is 3.0.7, targeting Node.js >=16. It uses libsodium's Secret key box for encryption, providing a scalable, stateless alternative to server-side session stores. Unlike other Koa session middlewares, it eliminates the need for a database or external cache. Key differentiator: client-side encryption using sodium-native, with support for both a high-entropy secretKey or a passphrase+salt combination. Release cadence: maintenance mode with occasional dependency updates.
npm install koa-encrypted-sessionVerified import paths — ran on the pinned version, not inferred.
Sets up encrypted cookie sessions with a secret key from environment variable and tracks view count per session.
Convert to ESM or use dynamic import() if in a CommonJS project.
Upgrade Node.js to v16 or later.
Generate a key using the provided CLI tool: koa-encrypted-session-gen-key
Always call middleware with (options, app).
Store only minimal data in session; use external store for larger payloads.
Use Buffer.from(key, 'base64') for base64-encoded keys or Buffer.from(key, 'hex') for hex keys.
Ensure app.use(encryptedSession(options, app)) is called with app as second argument.
Use import instead, or use dynamic import().