i am using passportjs for login.Its working fine for one login.when multiple logins are done,the “req.user” object does not seem to update,it is same for all sessions(i used two browsers for 2 logins but the “req.user” object is same)
Session problem
You can distinguish between the two sessions by using the cookie provided by the two browsers.
“express-session” is a npm module which does it for you.
You need to use the express-session middleware before app.use(passport.session()); to actually store the session in memory/database. This middleware is responsible for setting cookies to browsers and converts the cookies sent by browsers into req.session object.
Now each req.session object has a session id, which is different for each session.
Explore express-session on the net, you will get an idea of what you want.
Also note that multiple tabs of a browser / multi window of the same browser use the same cookie while making the requests.
You need two different browsers for different sessions.
I have already used express.session().session is being maintained fine.For multiple browser windows also the login is maintained.But the req.user object does not seem to change for different logins(i logged in to two browsers).how can I debug that thing?
You logged in the same user from two different browsers. Why should the req.user object be different? req.user gives the user details, thus single user will have same req.user object, irrespective of login.
No,I had logged in with a different user.still I seem to get the info of the first logged in user
I thought you were talking of single user. Give your project github link, I will look at it.
Here,its a chat app.First head to localhost:8161/signup for signup
Hint: There’s something wrong in serialisation and deserialisation of user. Try finding the error.