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 e01ef0a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 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,7 @@ const sessionUtils = {
},

getSessionID() {
const storedSession = storage.getItem('session_id')
const stored = storedSession
? JSON.parse(storedSession)
: this.newSession()
stored.ttl = new Date(stored.ttl)
const stored = this.storedSession() || this.newSession()

if (stored.ttl < Date.now()) {
stored.id = this.generateSessionID()
Expand Down

0 comments on commit e01ef0a

Please sign in to comment.