Skip to main content

getSessionCookieOptions()

getSessionCookieOptions merges the provided partial CookieOptions with the default values from CookieConfig. Any property you omit falls back to its default.

Signature

getSessionCookieOptions(options: Partial<CookieOptions>): CookieOptions

Parameters

ParameterTypeRequiredDescription
optionsPartial<CookieOptions>Cookie options to apply. Unspecified properties use the defaults from CookieConfig.

Returns

CookieOptions — A complete cookie options object with all required fields populated.

Default Values

PropertyDefault
httpOnlytrue
maxAge3600 seconds (1 hour)
sameSite'lax'
securetrue

Usage

Use Defaults with a Custom Lifetime

import { getSessionCookieOptions } from '@thunderid/node'

// Override only maxAge; all other properties use defaults
const options = getSessionCookieOptions({ maxAge: 86400 }) // 24 hours

Override Multiple Options

import { getSessionCookieOptions } from '@thunderid/node'

const options = getSessionCookieOptions({
maxAge: 7200,
sameSite: 'strict',
secure: true,
})
src/routes/callback.ts
import { CookieConfig, getSessionCookieOptions } from '@thunderid/node'

app.get('/callback', async (req, res) => {
const sessionId = req.cookies[CookieConfig.SESSION_COOKIE_NAME]

await auth.signIn(
(authUrl) => res.redirect(authUrl),
sessionId,
req.query.code as string,
req.query.session_state as string,
req.query.state as string,
)

res.cookie(
CookieConfig.SESSION_COOKIE_NAME,
sessionId,
getSessionCookieOptions({ maxAge: 3600 }),
)

res.redirect('/dashboard')
})
ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© WSO2 LLC. All rights reserved.Privacy PolicyCookie Policy