From 41f6f3f141aa3b2842b4daff4bdb19d30049959d Mon Sep 17 00:00:00 2001 From: dlohvinov Date: Fri, 22 Mar 2024 04:33:04 +0200 Subject: [PATCH] 24.04.16: userinfo logout if session expires in less than hour [WTEL-4374] --- package.json | 2 +- src/modules/Userinfo/store/UserinfoStoreModule.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6c3401c50..11924283f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webitel/ui-sdk", - "version": "24.4.15", + "version": "24.4.16", "private": false, "scripts": { "dev": "vite", diff --git a/src/modules/Userinfo/store/UserinfoStoreModule.js b/src/modules/Userinfo/store/UserinfoStoreModule.js index 09778ff46..b4f8c808f 100644 --- a/src/modules/Userinfo/store/UserinfoStoreModule.js +++ b/src/modules/Userinfo/store/UserinfoStoreModule.js @@ -93,12 +93,16 @@ export default class UserinfoStoreModule extends BaseStoreModule { userinfo = userinfoGenerator(instance); await context.dispatch('BEFORE_OPEN_SESSION_HOOK'); - // !!! it should be checked in router.js beforeEach hook - // if (!localStorage.getItem('access-token')) { - // context.dispatch('REDIRECT_TO_AUTH'); - // throw new Error('No access-token in localStorage'); - // } + + const HOUR_LENGTH = 60 * 60 * 1000; + const session = await userinfo.getSession(); + + if ((session.expiresAt - Date.now() < HOUR_LENGTH)) { + await context.dispatch('LOGOUT'); + throw new Error(`Session expires soon ${session.expiresAt}`); + } + await context.dispatch('SET_SESSION', session); const access = await userinfo.getApplicationsAccess(); await context.dispatch('SET_APPLICATIONS_ACCESS', new ApplicationsAccess({ access }).getAccess());