Skip to content

Commit

Permalink
remove currentAccount from session storage if token has expired (#637)
Browse files Browse the repository at this point in the history
* remove currentAccount from session storage if token has expired
  • Loading branch information
bolyachevets authored Aug 1, 2023
1 parent 92172b3 commit 93f82f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "name-request",
"version": "4.1.9",
"version": "4.1.10",
"private": true,
"appName": "Name Request UI",
"sbcName": "SBC Common Components",
Expand Down
11 changes: 10 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import KeycloakService from 'sbc-common-components/src/services/keycloak.service
import * as Sentry from '@sentry/browser'
import * as Integrations from '@sentry/integrations'
import { AllDesignationsList, ConversionTypes, Designations, RequestActions, UsaStateCodes } from '@/list-data'
import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'
import ConfigHelper from 'sbc-common-components/src/util/config-helper'

// NB: order matters - do not change
import 'quill/dist/quill.core.css'
Expand Down Expand Up @@ -104,7 +106,14 @@ async function syncSession () {
// Auto authenticate user only if they are not trying a login or logout
if (!isSigningIn() && !isSigningOut()) {
// Initialize token service which will do a check-sso to initiate session
await KeycloakService.initializeToken(null).then(() => {}).catch(err => {
await KeycloakService.initializeToken(null).then(() => {
const token = ConfigHelper.getFromSession(SessionStorageKeys.KeyCloakToken)
if (!token) {
// when there is no token in session storage, e.g. because token has expired due to user inactivity,
// make sure to clear out account info saved on previous login
ConfigHelper.removeFromSession(SessionStorageKeys.CurrentAccount)
}
}).catch(err => {
if (err?.message !== 'NOT_AUTHENTICATED') {
throw err
}
Expand Down

0 comments on commit 93f82f4

Please sign in to comment.