Skip to content

Commit

Permalink
add StoredSession method
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Nov 28, 2024
1 parent 96718df commit 398a6dd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/lib-classifier/src/store/utils/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
Expand Down

0 comments on commit 398a6dd

Please sign in to comment.