Skip to content

fix: allow creating empty sessions - #303

Open
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/create-secure-session-without-data-human-dco
Open

fix: allow creating empty sessions#303
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/create-secure-session-without-data-human-dco

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

FastifyInstance.createSecureSession(data?) is declared with optional data in types/index.d.ts and is exercised without an argument in the TypeScript tests. At runtime, calling createSecureSession() throws while Session initializes its timestamp, so integrations that need an empty session cannot use the public helper.

Fix

Default omitted data to an empty object at the createSecureSession decorator boundary. Existing object arguments are unchanged, and the regression assertion confirms the returned empty session is usable.

Tests

  • node --test test/decorators.test.js - passed; 3 tests
  • npm test - passed; 49 unit tests with 100 percent coverage and 16 TypeScript assertions
  • npm run lint - passed
  • git diff HEAD^ HEAD --check - passed

Compatibility

This changes only the previously failing omitted or undefined-data case to match the existing optional TypeScript contract. Sessions created with an object retain their current behavior.

Related issue

Independent reproduction; no issue linked.

Signed-off-by: lprnmns <manasalperen@gmail.com>
@lprnmns
lprnmns marked this pull request as ready for review August 31, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant