1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 21:10:05 +00:00

fix(session-expiry): discard and create new session if expired

This commit is contained in:
Krishna Acondy
2020-08-18 21:35:02 +01:00
parent 75a11cdff4
commit 68b864cf75
2 changed files with 14 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -4,4 +4,8 @@ export interface Session {
id: string;
state: string;
links: Link[];
attributes: {
sessionInactiveTimeout: number;
};
creationTimeStamp: string;
}