How to prevent session from overwriting another session

477 views Asked by At

I am trying to make a simple website that requests your email. However, when I open up my page on 2 different tabs and insert 2 different emails, the second one overwrites the first one.

app.get('/', function(req, res){
    sess = req.session;
    res.render('index.ejs');
});

app.get('/sending-email', function(req, res){
    sess = req.session;
    sess.email = req.query.to;
    res.end('done');
});

app.get('/someButtonClicked', function(req, res){
    sess = req.session;
    console.log(sess.email);
});

That is, on both tabs, whenever the button is clicked, "console.log(sess.email)" only prints out the most recent email. How do I make it so that they print their corresponding email? Any links/help would be greatly appreciated, thanks.

Below are the modules I'm using.

var session = require('express-session');
var connect = require('connect');
var SQLiteStore = require('connect-sqlite3')(session);
...
app.use(session({secret: 'blah', 
    resave: false, 
    saveUninitialized: true, 
    store: new SQLiteStore}));
1

There are 1 answers

0
Saim Ahmed On

"saveUninitialized: false" just because it's not created new record until current record not modified. and it overwrite.. Its my thought.