From 398a6dd26e8f5bd896bf7543199142db42ff8767 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Thu, 28 Nov 2024 12:47:05 +0000 Subject: [PATCH] add StoredSession method --- .../lib-classifier/src/store/utils/session.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/lib-classifier/src/store/utils/session.js b/packages/lib-classifier/src/store/utils/session.js index 7b268ed9225..cf70b54aa32 100644 --- a/packages/lib-classifier/src/store/utils/session.js +++ b/packages/lib-classifier/src/store/utils/session.js @@ -15,6 +15,16 @@ const sessionUtils = { return id }, + storedSession() { + const storedSession = storage.getItem('session_id') + if (storedSession) { + const session = JSON.parse(storedSession) + session.ttl = new Date(session.ttl) + return session + } + return null + }, + newSession() { return { id: this.generateSessionID(), @@ -23,11 +33,8 @@ const sessionUtils = { }, getSessionID() { - const storedSession = storage.getItem('session_id') - const stored = storedSession - ? JSON.parse(storedSession) - : this.newSession() - stored.ttl = new Date(stored.ttl) + const storedSession = this.storedSession() + const stored = storedSession || this.newSession() if (stored.ttl < Date.now()) { stored.id = this.generateSessionID()