hoangvvo / nextjs-mongodb-app

A Next.js and MongoDB web application, designed with simplicity for learning and real-world applicability in mind.
https://nextjs-mongodb.now.sh/
MIT License
1.54k stars 289 forks source link

Session not being remembered when revisiting site #66

Closed pkearney13 closed 4 years ago

pkearney13 commented 4 years ago

Describe the bug If you have logged into https://nextjs-mongodb.now.sh/ and quit chrome (completely quit the application) and you revisit the site https://nextjs-mongodb.now.sh/ your session is no longer valid and you need to log in again.

My understanding of sessions was that it would keep you logged in unless you log out or your session token expires?

To Reproduce Steps to reproduce the behavior:

Expected behavior Revisiting the site should keep you logged in

Desktop (please complete the following information):

hoangvvo commented 4 years ago

Hey @pkearney13, this is expected with the current code

https://github.com/hoangvvo/nextjs-mongodb-app/blob/10d7fcd2c3707d6183db9802d8159fcb99b2504e/middlewares/session.js#L13-L15

Simply add cookie.maxAge to a value (in second) to make the session remembered or else it will default to browser session (removed when browser is closed). See this.

But I agree that the session should be remembered. I will add a PR soon or feel free to do so!

pkearney13 commented 4 years ago

Ahhh that makes sense! I am following nextjs-mongodb-app as a template for a project I am building. I will add a PR if I get a chance thanks! 😄