express-session

how to manage multiple session in express js

醉酒当歌 提交于 2019-12-02 01:02:07
i am building a site that as two url ('/','/admin') session are conflicting here is my app.js session code app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(session({ secret: "JHGF>,./?;;LJ8#$?,KL:>>>,,KJJJDHE", resave: true, saveUninitialized: true })); app.use(flash()); app.use(passport.initialize()); app.use(passport.session()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use('/admin', admin); please how can i fix this? here is index.js var express = require('express

What's the difference between saveUninitialized and resave?

谁都会走 提交于 2019-11-30 11:45:27
The session middleware for Express provides several configurable options . resave : 'Forces the session to be saved back to the session store, even if the session was never modified during the request.' saveUninitialized : 'Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified.' It appears that both options are for saving unmodified sessions. What's the difference? I thought I would start off with a basic answer, my bit of understanding so far, and improve it together. Important question been 'dead' for too long. From this

Store session in operation hook - Loopback

拥有回忆 提交于 2019-11-30 09:55:38
问题 I want to store some data other than userId or accessToken to store in a session, in after save or before save operation hook in Loopback application using express-session . I have this in my server/server.js : .... const session = require('express-session'); const MongoStore = require('connect-mongo')(session); .... app.use(session({ name:'session-name', secret: 'keyboard cat', store: new MongoStore({url: 'mongodb://localhost/test', ttl:1}), resave: false, saveUninitialized: true })); And as

Store session in operation hook - Loopback

╄→尐↘猪︶ㄣ 提交于 2019-11-29 17:23:10
I want to store some data other than userId or accessToken to store in a session, in after save or before save operation hook in Loopback application using express-session . I have this in my server/server.js : .... const session = require('express-session'); const MongoStore = require('connect-mongo')(session); .... app.use(session({ name:'session-name', secret: 'keyboard cat', store: new MongoStore({url: 'mongodb://localhost/test', ttl:1}), resave: false, saveUninitialized: true })); And as I'm defining the remote-method with some parameters it actually passing the parameter and not the req

When to use saveUninitialized and resave in express-session

半城伤御伤魂 提交于 2019-11-28 16:06:23
I am newbie with the MEAN stack. I read the express-session github doc but there are some options which are unclear to me. Those options are saveUninitialized and resave . Can anyone please explain with examples what are the advatanges of using saveUninitialized and resave , and what will the effect be if we change the boolean values in those options. Syntax:- app.use(session({ resave: false, saveUninitialized: true, })) Let's assume that sessions are enabled globally (for all requests). When a client makes an HTTP request, and that request doesn't contain a session cookie, a new session will