UNPKG

@mojojs/core

Version:

Real-time web framework

53 lines (52 loc) 1.6 kB
import type { App } from './app.js'; import type { Context } from './context.js'; import type { SessionData } from './types.js'; /** * Session manager class. */ export declare class Session { /** * Name for session cookies, defaults to `mojo`. */ cookieName: string; /** * Path for session cookies, defaults to `/`. */ cookiePath: string; /** * Default time for sessions to expire in seconds from now, defaults to `3600`. The expiration timeout gets refreshed * for every request. Setting the value to `0` will allow sessions to persist until the browser window is closed, * this can have security implications though. */ expiration: number; /** * Set the `HttpOnly` value on all session cookies. */ httpOnly: boolean; /** * Set the `SameSite` value on all session cookies, defaults to `lax`. */ sameSite: 'lax' | 'strict' | 'none'; /** * Set the secure flag on all session cookies, so that browsers send them only over HTTPS connections. */ secure: boolean; _app: WeakRef<App>; constructor(app: App); /** * Decrypt cookie. */ static decrypt(secrets: string[], encrypted: string): Promise<string | null>; /** * Encrypt cookie. */ static encrypt(secret: string, value: string): Promise<string>; /** * Load session data from encrypted cookie. */ load(ctx: Context): Promise<SessionData | null>; /** * Store session data in encrypted cookie. */ store(ctx: Context, data: SessionData): Promise<void>; }