import { Request, Response } from "express"; import { Middleware } from "@swirl/api"; import { ObjectID } from "bson"; /** Contains a session for a single user. */ export default class Session { /** This session's id. */ readonly sid: string; /** This session's CSRF key. */ readonly csrfKey: string; /** This session's expiration timestamp. */ readonly expiration: Date; /** The user id of the user who owns this session. */ user: ObjectID; /** Construct given the sid and CSRF key. */ constructor(sid: string, csrfKey: string, expiration: Date); /** * Creates a new session by generating a random sid and csrfKey. * @param ttl the number of minutes this session will be valid for. */ static generate(ttl: number, user: ObjectID): Promise; /** The sessions Redis key. */ readonly redisKey: string; /** The user session Redis key. */ readonly userSessionKey: string; /** Injects the session onto a response by setting the cookies. */ inject(req: Request, res: Response): Promise; /** Clears all the cookies for this request. */ clear(req: Request, res: Response): void; } declare module "express" { interface Request { /** The valid user session or null if not logged in. */ session: Session; } } /** Validates sessions given the groups that are allowed. */ export declare class SessionValidator extends Middleware { /** The valid groups that are allowed to access this handler. */ private readonly groups; /** If true then CSRF key validation is disabled for this session validator. */ private _disableCSRF; /** Construct given the valid groups. */ constructor(...groups: string[]); /** Disables CSRF checking for this validator. */ disableCSRF(): SessionValidator; /** Validates the session */ run(req: Request, res: Response): Promise; }