Browse Source

session max age increased, session resave

CrazyDoctor 3 months ago
parent
commit
26883c1c34
3 changed files with 18 additions and 1 deletions
  1. 2 1
      src/index.ts
  2. 15 0
      src/middlewares/SessionRenewMiddleware.ts
  3. 1 0
      src/session/ISession.ts

+ 2 - 1
src/index.ts

@@ -66,7 +66,8 @@ class ServerApp {
 			options: {
 				static: path.resolve(__dirname, './static'),
 				sessionSecret: Guid.new(),
-				adminPassword: SHA256.hash(ServerConfig.adminPassword)
+				adminPassword: SHA256.hash(ServerConfig.adminPassword),
+				sessionMaxAge: 21600000
 			}
 		}).init().then((server) => {
 			server.start(() => {

+ 15 - 0
src/middlewares/SessionRenewMiddleware.ts

@@ -0,0 +1,15 @@
+import { Middleware } from 'org.crazydoctor.expressts';
+import {NextFunction, Request, Response} from 'express';
+import { ISession } from '../session/ISession';
+
+class SessionRenewMiddleware extends Middleware {
+	protected action = (req: Request, res: Response, next: NextFunction): any => {
+		const session: ISession = req.session as ISession;
+		session.lastAccess = new Date().getTime();
+		next();
+	};
+	protected order = 1;
+	protected route = null;
+}
+
+export default SessionRenewMiddleware;

+ 1 - 0
src/session/ISession.ts

@@ -5,4 +5,5 @@ export interface ISession extends Session {
 	isEditor: boolean;
 	login: string | null;
 	returnTo?: string;
+	lastAccess: number;
 }