0

I have a fundamental questions regarding to session handling in Nodejs that it would be great if someone can give a hint!

In my case I am building a node application that in my plan I want to have two sessions. One session that use by passportjs for identification user with its own expire date and maxAge and the other one is used for another activity of the user

I am also using connect-mongo to save sessions in db.

How can I tell to passportjs that which session that I made should be used? Based on what I could see passportjs uses the first session that I defined. how can I tell to passportjs to use session2 in the below code?

var express=require('express');
const path=require('path');
var bodyParser=require('body-parser');
var session1=require('express-session'); 
var session2=require('express-session');
var mongoose=require('mongoose');
var passport=require('passport');
var mongoSession1=require('connect-mongo')(session1);
var mongoSession2=require('connect-mongo')(session2);
mongoose.connect('mongodb://xxxx',{useMongoClient: true});
app.use(session1({
  secret:'test1',
  resave:false,
  saveUninitialized:false,
  store:new mongoSession1({
    mongooseConnection:mongoose.connection,
    ttl:24*60*60  //1 day in db
  }),
  cookie:{maxAge:24*60*60*1000}  // 1 day expire
}));
app.use(session2({
  secret:'test2',
  resave:false,
  saveUninitialized:false,
  store:new mongoSession1({
    mongooseConnection:mongoose.connection,
    ttl:60*60  //1 hour
  }),
  cookie:{maxAge:60*60*1000}  // 1 hour
}));

app.use(passport.initialize());
app.use(passport.session());
Sam
  • 167
  • 3
  • 14

1 Answers1

0

you can probably access them using these two line of code

req.session1
req.session2
Amir Hossein
  • 133
  • 5