跳到主要内容
版本:Next

SessionOptions

Hierarchy

  • Omit<CookieSetOptions, maxAge>
    • SessionOptions

Index

Properties

optionalContextStore

ContextStore?: new (ctx: any) => SessionStore

optionalautoCommit

autoCommit?: boolean

(boolean) automatically commit headers (default true).

decode

decode: (obj: Record<any, any>) => string

enable

enable: boolean

encode

encode: (str: string) => Record<any, any>

optionalexternalKey

externalKey?: ExternalKeys

External key is used the cookie by default, but you can use options.externalKey to customize your own external key methods.

genid

genid: () => string

key

key: string

cookie key (default is koa:sess)

optionalmaxAge

maxAge?: number | session

maxAge in ms (default is 1 days) “session” will result in a cookie that expires when session/browser is closed Warning: If a session cookie is stolen, this cookie will never expire

optionalprefix

prefix?: string

If you want to add prefix for all external session id, you can use options.prefix, it will not work if options.genid present.

optionalrenew

renew?: boolean

Renew session when session is nearly expired, so we can always keep user logged in. (default is false)

optionalrolling

rolling?: boolean

Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. default is false

Methods

optionalbeforeSave

  • beforeSave(ctx: any, session: ISession): void
  • Hook: before save session

optionalvalid

  • valid(ctx: any, session: Partial<ISession>): void
  • Hook: valid session value before use it