When I use express-session middleware, when does the session property in request object(request.session) gets available?
- Does it always stay available since the beginning when the server starts? when no session is made (no login) then session data is empty but
sessionproperty itself is always available onrequestobject. Is is this case? OR - does
sessionobject gets attached torequestonly when someone logs in? and when no user is logged in thenrequest.sessionis alwaysundefined. is it this?
The intention of this question is to know which, in typescript, out of the follow two type definition I have to use:
(one is using session? and in another session is used)
import { SessionData } from "express-session";
declare module "express-session" {
interface SessionData {
userId: string;
}
}
export interface MyContext {
session: SessionData;
}
OR
import { SessionData } from "express-session";
declare module "express-session" {
interface SessionData {
userId: string;
}
}
export interface MyContext {
session?: SessionData;
}