Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SessionHandler

A handler that maintains a Session for each browser session.

It looks up the session for each request based on a session cookie which contains a session ID. It stores the session when the response is ended in the session store.

The session is available on the routing context with .

Hierarchy

  • SessionHandler

Implements

Index

Properties

Static Readonly DEFAULT_COOKIE_HTTP_ONLY_FLAG

DEFAULT_COOKIE_HTTP_ONLY_FLAG: boolean

Default of whether the cookie has the HttpOnly flag set More info: https://www.owasp.org/index.php/HttpOnly

Static Readonly DEFAULT_COOKIE_SECURE_FLAG

DEFAULT_COOKIE_SECURE_FLAG: boolean

Default of whether the cookie has the 'secure' flag set to allow transmission over https only. More info: https://www.owasp.org/index.php/SecureFlag

Static Readonly DEFAULT_LAZY_SESSION

DEFAULT_LAZY_SESSION: boolean

Default of whether the session should be created lazily.

Static Readonly DEFAULT_NAG_HTTPS

DEFAULT_NAG_HTTPS: boolean

Default of whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPS

Static Readonly DEFAULT_SESSIONID_MIN_LENGTH

DEFAULT_SESSIONID_MIN_LENGTH: number

Default min length for a session id. More info: https://www.owasp.org/index.php/Session_Management_Cheat_Sheet

Static Readonly DEFAULT_SESSION_COOKIE_NAME

DEFAULT_SESSION_COOKIE_NAME: string

Default name of session cookie

Static Readonly DEFAULT_SESSION_COOKIE_PATH

DEFAULT_SESSION_COOKIE_PATH: string

Default path of session cookie

Static Readonly DEFAULT_SESSION_TIMEOUT

DEFAULT_SESSION_TIMEOUT: number

Default time, in ms, that a session lasts for without being accessed before expiring.

Methods

flush

  • Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.

    Parameters

    Returns PromiseLike<void>

  • Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.

    Parameters

    • ctx: RoutingContext
    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns SessionHandler

  • Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.

    Parameters

    Returns PromiseLike<void>

  • Flush a context session earlier to the store, this will allow the end user to have full control on the event of a failure at the store level. Once a session is flushed no automatic save will be performed at end of request.

    Parameters

    • ctx: RoutingContext
    • ignoreStatus: boolean
    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns SessionHandler

handle

newSession

  • Create a new session

    Parameters

    Returns Session

setCookieHttpOnlyFlag

  • Sets whether the 'HttpOnly' flag should be set for the session cookie. When set this flag instructs browsers to prevent Javascript access to the the cookie. Used as a line of defence against the most common XSS attacks.

    Parameters

    • httpOnly: boolean

    Returns SessionHandler

setCookieMaxAge

setCookieSameSite

  • Set the session cookie SameSite policy to use.

    Parameters

    • policy: CookieSameSite

    Returns SessionHandler

setCookieSecureFlag

  • Sets whether the 'secure' flag should be set for the session cookie. When set this flag instructs browsers to only send the cookie over HTTPS. Note that this will probably stop your sessions working if used without HTTPS (e.g. in development).

    Parameters

    • secure: boolean

    Returns SessionHandler

setCookieless

  • Use sessions based on url paths instead of cookies. This is an potential less safe alternative to cookies but offers an alternative when Cookies are not desired, for example, to avoid showing banners on a website due to cookie laws, or doing machine to machine operations where state is required to maintain.

    Parameters

    • cookieless: boolean

    Returns SessionHandler

setLazySession

  • Use a lazy session creation mechanism. The session will only be created when accessed from the context. Thus the session cookie is set only if the session was accessed.

    Parameters

    • lazySession: boolean

    Returns SessionHandler

setMinLength

  • Set expected session id minimum length.

    Parameters

    • minLength: number

    Returns SessionHandler

setNagHttps

  • Set whether a nagging log warning should be written if the session handler is accessed over HTTP, not HTTPS

    Parameters

    • nag: boolean

    Returns SessionHandler

setSessionCookieName

  • Set the session cookie name

    Parameters

    • sessionCookieName: string

    Returns SessionHandler

setSessionCookiePath

  • Set the session cookie path

    Parameters

    • sessionCookiePath: string

    Returns SessionHandler

setSessionTimeout

  • Set the session timeout

    Parameters

    • timeout: number

    Returns SessionHandler

setUser

  • Set the user for the session

    Parameters

    Returns PromiseLike<void>

  • Set the user for the session

    Parameters

    • context: RoutingContext
    • user: User
    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns SessionHandler

Static create

  • Create a session handler

    Parameters

    Returns SessionHandler

Generated using TypeDoc