Ogurchik
Ogurchik

Reputation: 75

Different number session during authentication with Nodejs

I reading this article on Medium I came to place where it write number of the sessions link on Pastbin

In this article written that after many times invocation of this command "client $ curl -X GET http://localhost:3000 -b cookie-file.txt" i must have got one and the same result. But in the output i have

Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
f559ee33-2928-41a0-94aa-39025578cbc6
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
fcc48f22-2000-44f5-8f19-13adb1bf8191
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
dc696106-10ea-413a-b60e-b1e725820311

I don't understand why i getting distinct number session.

Upvotes: 0

Views: 21

Answers (1)

Matt Kuhns
Matt Kuhns

Reputation: 1368

Try this:

    app.use((req, res, next) => {    
        req.session.init = "initProgram";  //this is very important for sessions, we need to initialize it for authentication.
        next();
    });

Everytime you call the route, you are creating a new session. When you call http://localhost:3000, initialize the session, then use the cookie on subsequent calls to only use that session.

Upvotes: 1

Related Questions