From a854eb3501e82b2c671652e8fc827dfd1eebac07 Mon Sep 17 00:00:00 2001 From: "Delilah C." <23665803+goplayoutside3@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:51:42 -0600 Subject: [PATCH] Remove ttl logic from session id (#7233) --- app/lib/session.coffee | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/lib/session.coffee b/app/lib/session.coffee index ef59a55019..21e7b7387f 100644 --- a/app/lib/session.coffee +++ b/app/lib/session.coffee @@ -1,29 +1,17 @@ -storage = window.sessionStorage ? window.localStorage +storage = window.sessionStorage stored = JSON.parse storage?.getItem('session_id') generateSessionID = () -> hash = require('hash.js') sha2 = hash.sha256() id = sha2.update("#{Math.random() * 10000 }#{Date.now()}#{Math.random() * 1000}").digest('hex') - ttl = fiveMinutesFromNow() - stored = {id, ttl} + stored = {id} try storage.setItem('session_id', JSON.stringify(stored)) stored getSessionID = () -> - {id, ttl} = JSON.parse(storage.getItem('session_id')) ? generateSessionID() - if ttl < Date.now() - {id} = generateSessionID() - else - ttl = fiveMinutesFromNow() - try - storage.setItem('session_id', JSON.stringify({id, ttl})) + {id} = JSON.parse(storage.getItem('session_id')) ? generateSessionID() id -fiveMinutesFromNow = () -> - d = new Date() - d.setMinutes(d.getMinutes() + 5) - d - module.exports = {generateSessionID, getSessionID}