Interface TypedSession<Schema>

interface TypedSession<Schema extends z.ZodTypeAny> {
    data: TypeOf<Schema>;
    id: string;
    isTyped: boolean;
    flash<Key extends string | number | symbol>(
        name: Key,
        value: TypeOf<Schema>[Key],
    ): void;
    get<Key extends string | number | symbol>(
        key: Key,
    ): null | TypeOf<Schema>[Key];
    has<Key extends string | number | symbol>(name: Key): boolean;
    set<Key extends string | number | symbol>(
        name: Key,
        value: TypeOf<Schema>[Key],
    ): void;
    unset<Key extends string | number | symbol>(name: Key): void;
}

Type Parameters

  • Schema extends z.ZodTypeAny

Properties

Methods

Properties

data: TypeOf<Schema>

The raw data contained in this session.

This is useful mostly for SessionStorage internally to access the raw session data to persist.

id: string

A unique identifier for this session.

Note: This will be the empty string for newly created sessions and sessions that are not backed by a database (i.e. cookie-based sessions).

isTyped: boolean

Marks a session as a typed session.

Methods

  • Sets a value in the session that is only valid until the next get(). This can be useful for temporary values, like error messages.

    Type Parameters

    • Key extends string | number | symbol

    Parameters

    Returns void

  • Returns true if the session has a value for the given name, false otherwise.

    Type Parameters

    • Key extends string | number | symbol

    Parameters

    Returns boolean

  • Sets a value in the session for the given name.

    Type Parameters

    • Key extends string | number | symbol

    Parameters

    Returns void

  • Removes a value from the session.

    Type Parameters

    • Key extends string | number | symbol

    Parameters

    Returns void