Giter VIP home page Giter VIP logo

Comments (9)

joewagner avatar joewagner commented on May 18, 2024

express-session's dependency on cookie-parser has been removed. That message should come up when the cookie isn't available in req.headers.cookie.
Is your app still working, as you would expect?
What version of express are you using?

from session.

leviathan747 avatar leviathan747 commented on May 18, 2024

The app is still working as expected. I'm using express 4.5.1 and express-session 1.6.4

from session.

joewagner avatar joewagner commented on May 18, 2024

Can you post a gist that reproduces the issue?

from session.

leviathan747 avatar leviathan747 commented on May 18, 2024

I found the issue (I'm relatively new to express). I had not declared req.headers.cookie. I added a line

req.headers.cookie = null;

and that solved the issue. I guess it was not able to access it because it didn't exist. Thanks for your time.

from session.

joewagner avatar joewagner commented on May 18, 2024

Its strange that req.headers.cookie = null; solves your issue. the deprecated message should only show up if the cookie is not available at req.headers.cookie, but was available in req.cookies, or req.signedCookies.

from session.

leviathan747 avatar leviathan747 commented on May 18, 2024

Here's the relevant snippet from my app.js. As I said I'm new to express so I may have a glaring mistake I just don't have the intuition to catch.

app.use(function(req, res, next) {
    req.db = db.db;
    req.encoder = new Encoder('entity');
    req.session = null;
    req.headers.cookie = null;
    next();
});

app.use(partials());
app.use(cookieParser());
app.use(session({
    secret: ''+new Date().getTime(),
    cookie: {secure: false},
    resave: true,
    saveUninitialized: true
}));

app.set('port', process.env.PORT || defaultPort);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: 'false'}));
app.use(express.static('public'));
app.use(express.static(path.join(__dirname, 'public')));

from session.

joewagner avatar joewagner commented on May 18, 2024

You shouldn't be doing anything to req.session, or req.headers.cookie directly.
You should be able to remove the cookieParser() middleware. Unless you need is for something else, and then you can put it after the session middleware.

from session.

dougwilson avatar dougwilson commented on May 18, 2024

The warning is because your secret is ''+new Date().getTime(), so it is different every time you restart the server and it's confusing the internals of this module. Your secret needs to be static. Also, remove app.use(cookieParser());

Its strange that req.headers.cookie = null; solves your issue

@joewagner it made the issue so away because it removed the cookies, essentially, so the module was no longer confused from having an invalid secret.

from session.

leviathan747 avatar leviathan747 commented on May 18, 2024

Thanks for the help!

from session.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.