express-session

Get cookie with react

ε祈祈猫儿з 提交于 2019-12-06 19:06:36
问题 I need to know if my user is connected or not. For that I want to read the cookies that I set in the server side with express-session : app.use(session({ secret: 'crypted key', resave: false, saveUninitialized: true, cookie: { secure: false } // Put true if https })) app.post('/connect_user', (req, res) => { req.session.cookie.username = req.body.username findUserData('username', req.body.username, req, (userData) => { req.session.cookie.id = userData.id req.session.cookie.username = userData

How do I have two Express sessions?

橙三吉。 提交于 2019-12-06 14:54:09
I have a Passport-using application with a GraphQL endpoint and a /logout endpoint. For some reason when I called request.isAuthenticated() from inside the GraphQL endpoint I got back true , but when I made the same exact call from inside the /logout endpoint I got back false . So, I did a bit of logging (of request.session.id ) and it turns out that I somehow wound up with two sessions. Stranger still, the session used by my GraphQL endpoint is persistent: if I restart the server it keeps the same ID, while the one in /logout keeps changing. I think that what's happening is that the

express-session: Rolling session expiry configuration

血红的双手。 提交于 2019-12-05 22:59:14
So I'm using express-session with a mongo store like so: app.use(session({ secret: 'some secret here', saveUninitialized: false, resave: false, store: new MongoStore({ url: 'http://someurlhere' }) })); I have some login middleware, which after a successful login I want to then set the session cookie expiry time. So I am testing with a 10 second expiry time right now using req.session.cookie.expires = new Date(Date.now() + 10000); I want the session expiry to reset for each subsequent request. Currently after 10 seconds have elapsed, no matter how many requests I have made after logging in, the

Get cookie with react

此生再无相见时 提交于 2019-12-04 22:53:14
I need to know if my user is connected or not. For that I want to read the cookies that I set in the server side with express-session : app.use(session({ secret: 'crypted key', resave: false, saveUninitialized: true, cookie: { secure: false } // Put true if https })) app.post('/connect_user', (req, res) => { req.session.cookie.username = req.body.username findUserData('username', req.body.username, req, (userData) => { req.session.cookie.id = userData.id req.session.cookie.username = userData.username res.redirect('/profil') }) }) I tried to use react-cookie but it doesn't work however I copy

req.session in express-session not persisting

匆匆过客 提交于 2019-12-04 10:38:19
问题 I have the following code: var express = require('express'); var cookieParser = require('cookie-parser'); var http = require('http') var app = express(); app.use(cookieParser()); var session = require('express-session'); app.use(session({ resave: false, saveUninitialized: true, secret: 'sdlfjljrowuroweu', cookie: { secure: true } })); app.get('/test', test); function test(req, res) { var sess = req.session; console.log('before', sess); if (sess.views) { sess.views++ req.session.save(); res

Can't save express session in NodeJs

我们两清 提交于 2019-12-04 06:28:53
问题 I'm trying to save the userName of a user in express session. It saves the variable in session but it returns undefined on next request to the route. However, the problem is with POST route only. With GET request, I can save session variable and it doesn't get destroyed on further requests. I think I must be doing something wrong. I tried save() method for POST but still it saves only first time and next time it is vanished. Here's the code: app.use(session({ secret: 'some secret', resave:

req.session in express-session not persisting

丶灬走出姿态 提交于 2019-12-03 06:16:05
I have the following code: var express = require('express'); var cookieParser = require('cookie-parser'); var http = require('http') var app = express(); app.use(cookieParser()); var session = require('express-session'); app.use(session({ resave: false, saveUninitialized: true, secret: 'sdlfjljrowuroweu', cookie: { secure: true } })); app.get('/test', test); function test(req, res) { var sess = req.session; console.log('before', sess); if (sess.views) { sess.views++ req.session.save(); res.setHeader('Content-Type', 'text/html') res.write('<p>views: ' + sess.views + '</p>') res.write('<p

Express-session Secure Cookies not working

痴心易碎 提交于 2019-12-02 03:58:10
When not using secure cookie true setting, my app user login works fine. When I enable secure cookies, the login appears to go through fine, but it seems the cookie is not saved and the user is not logged in. In other words, this works: app = express(); app.use(session({ secret: 'secret code', store: sessionStore, resave: false, saveUninitialized: false, cookie: { secure: false, maxAge: 5184000000 // 60 days } })); This does not work (user isn't able to log in): app = express(); app.set('trust proxy'); app.use(session({ secret: config.cookieSecret, store: sessionStore, resave: false,

Express-session Secure Cookies not working

依然范特西╮ 提交于 2019-12-02 03:05:40
问题 When not using secure cookie true setting, my app user login works fine. When I enable secure cookies, the login appears to go through fine, but it seems the cookie is not saved and the user is not logged in. In other words, this works: app = express(); app.use(session({ secret: 'secret code', store: sessionStore, resave: false, saveUninitialized: false, cookie: { secure: false, maxAge: 5184000000 // 60 days } })); This does not work (user isn't able to log in): app = express(); app.set(

how to manage multiple session in express js

≯℡__Kan透↙ 提交于 2019-12-02 01:35:06
问题 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