express-session

Every time React sends request to Express, a new session is generated

别来无恙 提交于 2020-06-27 12:59:05
问题 I use React as a client to send request to Express with proxy and express-session set up. But every time React makes a request to Express server, a new session is created. So I checked Express alone by manually accessing to the same api url and it keep using the same session each time I refresh the page. Project structure: project-folder - client // React client with proxy set up + src + package.json + ... - server.js - package.json Inside server.js : const session = require('express-session'

express session not saving for Ipad

泄露秘密 提交于 2020-05-13 05:03:32
问题 I am trying to save a session variable for a user when they login. This works on the computer, but when I try it on an iPad using Safari or Chrome it doesn't save. Here is where I set up my session: app.set('trust proxy', 1) app.use(session({ secret: crypto.randomBytes(20).toString('hex'), resave: false, duration: 60 * 60 * 1000, activeDuration: 10 * 60 * 1000, saveUninitialized: false, cookieName: 'session', cookie: { secure: true } })) I use this route to set up the user: .get('/checkLogin'

express session not saving for Ipad

拜拜、爱过 提交于 2020-05-13 05:00:17
问题 I am trying to save a session variable for a user when they login. This works on the computer, but when I try it on an iPad using Safari or Chrome it doesn't save. Here is where I set up my session: app.set('trust proxy', 1) app.use(session({ secret: crypto.randomBytes(20).toString('hex'), resave: false, duration: 60 * 60 * 1000, activeDuration: 10 * 60 * 1000, saveUninitialized: false, cookieName: 'session', cookie: { secure: true } })) I use this route to set up the user: .get('/checkLogin'

Cookie not set with express-session in production

只谈情不闲聊 提交于 2020-05-12 02:53:53
问题 My app is divided between Client and Server. Client is a frontend side Nextjs app hosted on Now.sh, Server is its backend created with Express and hosted on Heroku, so the domains are client-app.now.sh and server-app.herokuapp.com . Authentication Authentication system is based on cookies and I'm using express-session to achieve it. This is my express-session configuration app.use( session({ store: process.env.NODE_ENV === "production" ? new RedisStore({ url: process.env.REDIS_URL }) : new

Cookie not set with express-session in production

巧了我就是萌 提交于 2020-05-12 02:51:11
问题 My app is divided between Client and Server. Client is a frontend side Nextjs app hosted on Now.sh, Server is its backend created with Express and hosted on Heroku, so the domains are client-app.now.sh and server-app.herokuapp.com . Authentication Authentication system is based on cookies and I'm using express-session to achieve it. This is my express-session configuration app.use( session({ store: process.env.NODE_ENV === "production" ? new RedisStore({ url: process.env.REDIS_URL }) : new

Node.js How to get previous url

戏子无情 提交于 2020-04-16 05:47:33
问题 I want to get previous url, for example in all my /admin routes I open a form where the admin needs to re-enter his password to get redirected to the route he requested, but the problem is after I validate his password and I try to redirect him to the route he initially requested, I don't have this route anymore, it's lost. For example, admin requests /admin/register, a form appears that posts to validate-password , and then if it finds that the password matches (correct password entered), it

Get “undefined” for req.session in nodejs

故事扮演 提交于 2020-03-05 06:57:13
问题 Noob here, and I tried to have a session to do the login attempt count in nodejs, but it seem the session is not declared in route as it just show undefined when i console.log it. Below is my code : Server.js var express = require('express'); var session = require('express-session'); var cors = require('cors'); var bodyParser = require("body-parser"); var app = express(); var port = process.env.PORT || 3000; app.use(bodyParser.json()); app.use(cors()); app.use(session({ resave: false,

Get “undefined” for req.session in nodejs

淺唱寂寞╮ 提交于 2020-03-05 06:57:03
问题 Noob here, and I tried to have a session to do the login attempt count in nodejs, but it seem the session is not declared in route as it just show undefined when i console.log it. Below is my code : Server.js var express = require('express'); var session = require('express-session'); var cors = require('cors'); var bodyParser = require("body-parser"); var app = express(); var port = process.env.PORT || 3000; app.use(bodyParser.json()); app.use(cors()); app.use(session({ resave: false,

req.session.destroy and passport logout aren't destroying cookie on client side

夙愿已清 提交于 2020-01-16 16:57:11
问题 I'm trying to destroy the cookie on the client side but can't seem to figure out how to. I've tried the few ways that passport and some answers on SO provided but I'm at a loss as to how to clear the actual cookie. My code so far is: app.get('/logout', function (req, res){ sessionStore.destroy(req.sessionID, (err) =>{ if(err)console.log(err); req.logout(); req.session.destroy(function (err) { if(err) console.log(err); res.status(200).json({message : 'User Logged Out'}); }); }); }); I have

When to use saveUninitialized and resave in express-session

此生再无相见时 提交于 2019-12-28 07:58:26
问题 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, })) 回答1: Let's assume that sessions are enabled globally (for all requests).