Creates an in-memory session store.
@eryx/http/ServerSession Module
Summary
Functions
SessionMethods:clear() → ()
SessionMethods:destroy() → ()
API Reference
Functions
SessionMethods:delete
SessionMethods:clear
SessionMethods:clear() → ()
SessionMethods:regenerate
SessionMethods:destroy
SessionMethods:destroy() → ()
MemoryStoreMethods:get
MemoryStoreMethods:set
MemoryStoreMethods:delete
FileStoreMethods:get
FileStoreMethods:set
FileStoreMethods:delete
SqliteStoreMethods:get
SqliteStoreMethods:set
SqliteStoreMethods:delete
ServerSession.memoryStore
Returns
SessionStore
ServerSession.fileStore
Creates a filesystem-backed session store where each session is stored as JSON.
Parameters
Directory used for session files.
Returns
SessionStore
ServerSession.sqliteStore
Creates an SQLite-backed session store.
Parameters
Either a path string or an open @eryx/sqlite3 database.
Optional table name. Defaults to "http_sessions".
Returns
SessionStore
ServerSession.middleware
Creates app middleware that attaches a server-side session to ctx.session.
The middleware loads the session from a cookie before the handler runs and persists it back to the configured store after the handler completes.
Parameters
Session configuration and backing store.
Returns
Types
SessionRecord
SessionStore
type SessionStore = {
get: ((self: SessionStore, id: string) → SessionRecord?),
set: (
self: SessionStore,
id: string,
data: { [string]: any },
expiresAt: number?
) → (),
delete: ((self: SessionStore, id: string) → ()),
touch: (((self: SessionStore, id: string, expiresAt: number?) → ()))?
}
SessionCookieOptions
type SessionCookieOptions = {
path: string?,
domain: string?,
secure: boolean?,
httpOnly: boolean?,
sameSite: "Strict" | "Lax" | "None"?
}
sameSite: "Strict" | "Lax" | "None"?
SessionOptions
type SessionOptions = {
store: SessionStore?,
cookieName: string?,
ttl: number?,
rolling: boolean?,
cookie: SessionCookieOptions?
}
Session
type Session = {
id: string?,
data: { [string]: any },
isNew: boolean,
destroyed: boolean,
get: ((self: Session, key: string) → any),
set: ((self: Session, key: string, value: any) → ()),
delete: ((self: Session, key: string) → ()),
clear: ((self: Session) → ()),
regenerate: ((self: Session) → string),
destroy: ((self: Session) → ())
}
Removes a value and marks the session dirty.
Session:clear() → ()
Clears all session data.
Assigns a fresh session id and preserves the current data.
Session:destroy() → ()
Deletes the session from the backing store and clears the cookie.