Setu-TS
    Preparing search index...

    Interface ISession

    Per-request session handle.

    Obtained from ISessionService.from (or the plugin's getSession helper). Mutations are buffered and written back by the session middleware after the handler returns, so a handler never issues a Set-Cookie itself.

    const session = getSession(ctx);
    session.set('cartId', cart.id);
    const userId = session.get<string>('userId');

    0.2.0

    interface ISession {
        id: string;
        isNew: boolean;
        clear(): void;
        delete(key: string): boolean;
        destroy(): void;
        get<T = unknown>(key: string): T | undefined;
        has(key: string): boolean;
        regenerate(): void;
        set<T>(key: string, value: T): void;
        toJSON(): SessionData;
    }
    Index
    id: string

    The session identifier. Stable for the session's lifetime until ISession.regenerate is called.

    isNew: boolean

    Whether this session was created for this request rather than restored from a cookie. true for a first visit, and for a request whose cookie was missing, expired, or failed authentication.

    • Reads a value.

      Type Parameters

      • T = unknown

        The expected value type; validate before trusting it, since the payload survived a JSON round-trip

      Parameters

      • key: string

        Session key

      Returns T | undefined

      The value, or undefined when absent

    • Issues a new session id while keeping the current data.

      Call this on privilege change (most importantly immediately after login) so that a session id an attacker planted before authentication does not carry into the authenticated session — session fixation. On the store strategy the previous entry is deleted, making this a real revocation.

      Returns void

    • Writes a value and marks the session for commit.

      Passing undefined removes the key instead of storing it. undefined is not JSON-serializable, so storing it would make ISession.has report a key that serialization then drops — presence would be true before a commit and false after the next load.

      Type Parameters

      • T

        The value type

      Parameters

      • key: string

        Session key

      • value: T

        Value to store; must be JSON-serializable. undefined removes the key

      Returns void