express-session

TypeScript: Extend Express.Session interface with own class

北慕城南 提交于 2021-02-08 15:00:27
问题 I'm working on a Typescript project with npm packages. I want to add a property to the Express.Session interface. example Class: class User { name: string; email: string; password: string; } export = User; New d.ts file for the interface definition (don't want to edit express-session.d.ts): declare namespace Express { interface Session { user: User } } app.ts import User = require('./User'); function (req: express.Request, res: express.Response) { req.session.user //I want to use it like this

How to clear req.session on clearing browser cookies in node js?

匆匆过客 提交于 2021-01-27 18:53:42
问题 I am using "express": "~4.14.0" with express-session for saving username. Once the user is logged in, I will save the user name in req.session.authorizedUser = username to display it in the application header. When either the browser history is cleared or the browser is closed, I want to clear the session. Please suggest me if there is any way to clear the session when doing any of these two operations. I have tried setting the maxAge option for session cookies, as shown below, but it doesn't

How to declare additional properties using declaration merging? Without overwriting the module?

雨燕双飞 提交于 2021-01-01 09:23:25
问题 Well I am using express-session, with the typing from definity types ( @types/express-session ) I notice that the types don't have anything for custom data in the session fields. Which is not that useful. I wish to extend this to contain (say) userId: number . The file @types/express-session show it can be done using: /** * This interface allows you to declare additional properties on your session object using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration

Javascript how to reference an Express-Session on the client

家住魔仙堡 提交于 2020-12-12 09:55:06
问题 In my server I have created an express-session. I want to store in this a check for if the user has logged in or not. I do not know how to access this express-session on the non-server side of the code. Basically if the user is logged in I will then edit a page the user sees. I will only know to edit the page if the user is logged in or not which would require me to access the express session. 回答1: You cannot access session data directly from the client. It is stored server-side only. The

Javascript how to reference an Express-Session on the client

狂风中的少年 提交于 2020-12-12 09:54:48
问题 In my server I have created an express-session. I want to store in this a check for if the user has logged in or not. I do not know how to access this express-session on the non-server side of the code. Basically if the user is logged in I will then edit a page the user sees. I will only know to edit the page if the user is logged in or not which would require me to access the express session. 回答1: You cannot access session data directly from the client. It is stored server-side only. The

set up mssql-session-store in node.js

左心房为你撑大大i 提交于 2020-12-05 12:40:13
问题 I'm trying to use mssql-session-store as nodejs (express) store for session: https://www.npmjs.com/package/mssql-session-store This is how it should be configured(from npm page): app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: false, store: new MssqlStore(options) // see options below })); var options = { connection: existingConnection, ttl: 3600, reapInterval: 3600, reapCallback: function() { console.log('expired sessions were removed); } }; My problem is with the

Session auto logout after inactivity

故事扮演 提交于 2020-11-30 06:10:27
问题 Is there a built in feature in express session, to enable auto logout after given time of inactivity ? I am using it as below, and want it to logout if session is inactive for half an hour. app.use(session({ key: 'sessid', secret: 'This is secret', resave: true, saveUninitialized: true, store: new RedisStore(redisOptions), cookie: { path: '/', httpOnly: true, secure: false, maxAge: 24 * 60 * 60 * 1000, signed: false } })) 回答1: Ok, I'll throw my two cents into the ring here. Even though it's