[]previous and next page

Session

The session of one request.

The session of one request.

Import#

ts
import type { Session } from "@shadow-js/dusk/server";

Signature#

ts
interface Session {
  /** The current id (changes on `regenerate` and on rotation). */
  readonly id: string;
  /** True when no valid session came with the request. */
  readonly isNew: boolean;
  get<T = unknown>(key: string): T | undefined;
  set(key: string, value: unknown): void;
  delete(key: string): void;
  /** Removes all data, keeping the session. */
  clear(): void;
  /**
   * Gives the session a new id and keeps its data; the old id stops working immediately. Call it
   * when the user signs in.
   */
  regenerate(): void;
  /** Ends the session: the record is deleted and the cookie removed. */
  destroy(): void;
}

Members#

Name Type Description
id readonly id: string The current id (changes on regenerate and on rotation).
isNew readonly isNew: boolean True when no valid session came with the request.
get get<T = unknown>(key: string): T | undefined
set set(key: string, value: unknown): void
delete delete(key: string): void
clear clear(): void Removes all data, keeping the session.
regenerate regenerate(): void Gives the session a new id and keeps its data; the old id stops working immediately. Call it when the user signs in.
destroy destroy(): void Ends the session: the record is deleted and the cookie removed.