Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ declare namespace fastifySession {
regenerate(): Promise<void>;
regenerate(ignoreFields: string[]): Promise<void>;

/** Set the session cookie options for this request handler. */
options(opts: Partial<CookieOptions>): void

/** Allows to destroy the session in the store. */
destroy(callback: Callback): void;
destroy(): Promise<void>;
Expand Down
18 changes: 17 additions & 1 deletion types/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import fastify, {
} from 'fastify'
import Redis from 'ioredis'
import { expectAssignable, expectNotAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd'
import { CookieOptions, MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..'
import fastifySession, { CookieOptions, MemoryStore, SessionStore } from '..'

const plugin = fastifySession

class EmptyStore {
set (_sessionId: string, _session: any, _callback: Function) {}
Expand Down Expand Up @@ -126,6 +128,20 @@ app.route({
expectType<Promise<void>>(request.session.regenerate())
expectType<Promise<void>>(request.session.regenerate(['foo']))
expectType<Promise<void>>(request.session.save())
expectError(request.session.options({ keyNotInCookieOptions: true }))
expectError(request.session.options({ signed: true }))
expectType<void>(request.session.options({}))
expectType<void>(request.session.options({
domain: 'example.com',
expires: new Date(),
httpOnly: true,
maxAge: 1000,
partitioned: true,
path: '/',
sameSite: 'lax',
priority: 'low',
secure: 'auto'
}))
}
})

Expand Down