Interface SessionIdStorageStrategy<Data, FlashData>

SessionIdStorageStrategy is designed to allow anyone to easily build their own SessionStorage using createSessionStorage(strategy).

This strategy describes a common scenario where the session id is stored in a cookie but the actual session data is stored elsewhere, usually in a database or on disk. A set of create, read, update, and delete operations are provided for managing the session data.

interface SessionIdStorageStrategy<Data, FlashData> {
    cookie?: Cookie | CookieParseOptions & CookieSerializeOptions & CookieSignatureOptions & {
        name?: string;
    };
    createData: ((data: Partial<Data & {
        [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
    }>, expires?: Date) => Promise<string>);
    deleteData: ((id: string) => Promise<void>);
    readData: ((id: string) => Promise<null | Partial<Data & {
        [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
    }>>);
    updateData: ((id: string, data: Partial<Data & {
        [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
    }>, expires?: Date) => Promise<void>);
}

Type Parameters

Properties

cookie?: Cookie | CookieParseOptions & CookieSerializeOptions & CookieSignatureOptions & {
    name?: string;
}

The Cookie used to store the session id, or options used to automatically create one.

createData: ((data: Partial<Data & {
    [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
}>, expires?: Date) => Promise<string>)

Creates a new record with the given data and returns the session id.

deleteData: ((id: string) => Promise<void>)

Deletes data for a given session id from the data store.

readData: ((id: string) => Promise<null | Partial<Data & {
    [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
}>>)

Returns data for a given session id, or null if there isn't any.

updateData: ((id: string, data: Partial<Data & {
    [Key in string | number | symbol as `__flash_${Key & string}__`]: FlashData[Key]
}>, expires?: Date) => Promise<void>)

Updates data for the given session id.