From 68b864cf75093bd00f95179244a0383e3c66a666 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 18 Aug 2020 21:35:02 +0100 Subject: [PATCH] fix(session-expiry): discard and create new session if expired --- src/SessionManager.ts | 10 ++++++++++ src/types/Session.ts | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/SessionManager.ts b/src/SessionManager.ts index 69b40a7..6f9bda0 100644 --- a/src/SessionManager.ts +++ b/src/SessionManager.ts @@ -17,6 +17,16 @@ export class SessionManager { await this.createSessions(accessToken); this.createAndWaitForSession(accessToken); const session = this.sessions.pop(); + const secondsSinceSessionCreation = + (new Date().getTime() - new Date(session!.creationTimeStamp).getTime()) / + 1000; + if ( + secondsSinceSessionCreation >= session!.attributes.sessionInactiveTimeout + ) { + await this.createSessions(accessToken); + const freshSession = this.sessions.pop(); + return freshSession; + } return session; } diff --git a/src/types/Session.ts b/src/types/Session.ts index b05e7da..a982063 100644 --- a/src/types/Session.ts +++ b/src/types/Session.ts @@ -4,4 +4,8 @@ export interface Session { id: string; state: string; links: Link[]; + attributes: { + sessionInactiveTimeout: number; + }; + creationTimeStamp: string; }