Skip to content

Commit 07f1611

Browse files
fix(types): add missing SessionObject#options() definition (#289)
Use the `CookieOptions` interface since it's more local (& seems accurate.) Thanks to @CamParry for identifying that. Note: eslint on latest complained about the imports in the type, so I had to split them up. (Specifically it emitted `import-x/no-named-default` when run against the imports as originally authored, then `import-x/no-duplicates` when I split up the imports.) Fixes #279. I had to split up the import in types/t
1 parent d0d3bd5 commit 07f1611

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

types/types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ declare namespace fastifySession {
7575
regenerate(): Promise<void>;
7676
regenerate(ignoreFields: string[]): Promise<void>;
7777

78+
/** Set the session cookie options for this request handler. */
79+
options(opts: Partial<CookieOptions>): void
80+
7881
/** Allows to destroy the session in the store. */
7982
destroy(callback: Callback): void;
8083
destroy(): Promise<void>;

types/types.test-d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import fastify, {
88
} from 'fastify'
99
import Redis from 'ioredis'
1010
import { expectAssignable, expectNotAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd'
11-
import { CookieOptions, MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..'
11+
import fastifySession, { CookieOptions, MemoryStore, SessionStore } from '..'
12+
13+
const plugin = fastifySession
1214

1315
class EmptyStore {
1416
set (_sessionId: string, _session: any, _callback: Function) {}
@@ -126,6 +128,20 @@ app.route({
126128
expectType<Promise<void>>(request.session.regenerate())
127129
expectType<Promise<void>>(request.session.regenerate(['foo']))
128130
expectType<Promise<void>>(request.session.save())
131+
expectError(request.session.options({ keyNotInCookieOptions: true }))
132+
expectError(request.session.options({ signed: true }))
133+
expectType<void>(request.session.options({}))
134+
expectType<void>(request.session.options({
135+
domain: 'example.com',
136+
expires: new Date(),
137+
httpOnly: true,
138+
maxAge: 1000,
139+
partitioned: true,
140+
path: '/',
141+
sameSite: 'lax',
142+
priority: 'low',
143+
secure: 'auto'
144+
}))
129145
}
130146
})
131147

0 commit comments

Comments
 (0)