Search code examples
node.jssessionuniquesessionid

How to make sessions unique for each user? - Node.js


I am working on a node project at the moment and my problem is that if I log into the website on one computer and I do the same for the other computer I will still be logged in into the account. I think this has to do with a problem with making the sessions unique.Here is the middleware that I am using for the session:

app.use(session({
    secret:"HelloWorld"
}));

If anyone wants to see the node file here it is: http://pastebin.com/euatwkNS

Any help would be greatly appreciated!


Solution

  • Have you tried using genid method.

    app.use(session({
        genid: function(req) { return uuid(); },
        secret:"HelloWorld"
    }));
    

    You already have uuid imported. It should work.

    NOTE be careful to generate unique IDs so your sessions do not conflict.

    More info in: express-session