Skip to main content
Deno 2 is finally here 🎉️
Learn more
Very Popular
Latest
interface LazySessionFlavor
import { type LazySessionFlavor } from "https://deno.land/x/grammy@v1.30.1/convenience/session.ts";

A lazy session flavor is a context flavor that holds a promise of some session data under ctx.session.

Lazy session middleware will provide this promise lazily on the context object. Once you access ctx.session, the storage will be queried and the session data becomes available. If you access ctx.session again for the same context object, the cached value will be used. Check out the documentation on lazy session middleware to know more, and read the section about lazy sessions on the website.

Methods

getter
session(): MaybePromise<S>

Session data on the context object, potentially a promise.

WARNING: You have to make sure that your session data is not undefined by providing a default value to the session middleware, or by making sure that ctx.session is assigned if it is empty! The type system does not include | undefined because this is really annoying to work with.

Accessing ctx.session by reading or writing will throw iff getSessionKey(ctx) === undefined holds for the respective context object ctx.

setter
session(session: MaybePromise<S | null | undefined>)