Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend session with "remember me" #281

Merged
merged 2 commits into from
Mar 23, 2021
Merged

Extend session with "remember me" #281

merged 2 commits into from
Mar 23, 2021

Conversation

psvenk
Copy link
Member

@psvenk psvenk commented Mar 18, 2021

Closes #246. Instead of just storing the username in client-side storage and populating it on the login page, keep the user logged in for up to 30 days if they select "remember me".

Please note that I have not yet tested this code.

Instead of just storing the username in client-side storage and
populating it on the login page, keep the user logged in for up to 30
days if they select "remember me".
@psvenk psvenk added this to the 2.7.1 milestone Mar 18, 2021
@psvenk
Copy link
Member Author

psvenk commented Mar 18, 2021

I just now tested this code with the following change applied so that I would not need to wait for 8 hours:

diff --git a/serve.js b/serve.js
index b0df969..b9f1415 100644
--- a/serve.js
+++ b/serve.js
@@ -108,10 +108,10 @@ app.use(express.static(__dirname + '/public'));
 app.use(bodyParser.urlencoded({ extended: true })); // Allows form submission
 app.use(bodyParser.json()); // json parser
 app.use(session({
-    // Sessions expire every 8 hours
-    cookie: { maxAge: 8 * 60 * 60 * 1000 },
-    // Check for expired sessions once per hour
-    store: new MemoryStore({ checkPeriod: 60 * 60 * 1000 }),
+    // Sessions expire every minute
+    cookie: { maxAge: 60 * 1000 },
+    // Check for expired sessions once per second
+    store: new MemoryStore({ checkPeriod: 1000 }),
     resave: false,
     saveUninitialized: false,
     secret: crypto.randomBytes(64).toString('hex'),

Without "remember me", my sessions expired after a minute; with "remember me", they were still valid after more than two minutes. I would like someone else to do some testing if possible before we merge this.

@psvenk psvenk requested a review from tektaxi March 19, 2021 17:11
@psvenk psvenk merged commit 57c7ee1 into master Mar 23, 2021
@psvenk psvenk deleted the remember-me branch March 23, 2021 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make "remember me" extend the session
1 participant