Session: Get no session?

Created on 30 May 2018  路  3Comments  路  Source: expressjs/session

const express = require('express');
const app = express();
const session = require('express-session');

app.use(session({
  secret: 'key', 
  resave: false,
  saveUninitialized: true, 
  cookie: {
    maxAge: 100000, 
    secure: true
  },
}));

app.post('/a',function(req, res) {
  req.session.name = 'Thomas';
});

app.post('/b', function(req, res) {
  console.log(req.session.name) //undefined
});

I have two requests for a and B, set up session through a, and then undefined when visiting B. Why?

question

Most helpful comment

I solved the problem, which is the default of fetch not sending cookied.

All 3 comments

secure: true is saving the cookie to https are you accessing this via http? if you are accessing this via http it will return no cookie.

secure :false I've set it up, but it doesn't work.

I solved the problem, which is the default of fetch not sending cookied.

Was this page helpful?
0 / 5 - 0 ratings