From 324c2ac3e6b49dbc61dd1497ed3817aa5783e5d6 Mon Sep 17 00:00:00 2001 From: Shaun Ford Date: Wed, 24 May 2017 14:09:40 -0700 Subject: [PATCH] Make sure 'remove timeout' methods are dispatched --- app/actions/authenticationActions.js | 18 ++++++++++-------- app/reducers/authenticationReducer.js | 1 - package.json | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/actions/authenticationActions.js b/app/actions/authenticationActions.js index 1b5b52b..39b3e15 100644 --- a/app/actions/authenticationActions.js +++ b/app/actions/authenticationActions.js @@ -80,10 +80,12 @@ function handleUserLogin(response, dispatch, redirectToWelcome=true) { let timeToExpireTokenInMillis = tokenExpiresDate.getTime() - now.getTime() - setTimeout(() => { + let sessionWarningTimeoutId = setTimeout(() => { dispatch(warnSessionExpiresSoon(token)) }, timeToExpireTokenInMillis - 120000) // warn two minutes before expiration + dispatch(setSessionWarningTimeoutId(sessionWarningTimeoutId)) + let authTokenTimeoutId = setTimeout(() => { dispatch(handleSessionExpiration()) }, timeToExpireTokenInMillis) @@ -193,8 +195,8 @@ export function refreshAuth(token, redirectPath='/', redirect=true) { timeout: AUTH_ACTION_TIMEOUT }) .then(function (response) { - handleRemoveAuthTokenTimeout() - handleRemoveSessionWarningTimeout() + dispatch(handleRemoveAuthTokenTimeout()) + dispatch(handleRemoveSessionWarningTimeout()) handleUserLogin(response, dispatch, false) if (redirect) { hashHistory.push(redirectPath) @@ -221,12 +223,12 @@ export function logoutUser(token) { timeout: AUTH_ACTION_TIMEOUT }) .then(function () { - dispatch(resetAuthState()) sessionStorage.removeItem('token') sessionStorage.removeItem('tokenExpiresDate') sessionStorage.removeItem('userRespondedToSessionWarning') - handleRemoveAuthTokenTimeout() - handleRemoveSessionWarningTimeout() + dispatch(handleRemoveAuthTokenTimeout()) + dispatch(handleRemoveSessionWarningTimeout()) + dispatch(resetAuthState()) dispatch(headerActions.mouseOutUsername()) hashHistory.push('/login') }) @@ -245,8 +247,8 @@ export function handleSessionExpiration() { sessionStorage.removeItem('token') sessionStorage.removeItem('tokenExpiresDate') sessionStorage.removeItem('userRespondedToSessionWarning') - handleRemoveAuthTokenTimeout() - handleRemoveSessionWarningTimeout() + dispatch(handleRemoveAuthTokenTimeout()) + dispatch(handleRemoveSessionWarningTimeout()) dispatch(expireSession()) dispatch(modalActions.clearAllModals()) dispatch(manageSDBActions.resetToInitialState()) diff --git a/app/reducers/authenticationReducer.js b/app/reducers/authenticationReducer.js index d8187fe..370b680 100644 --- a/app/reducers/authenticationReducer.js +++ b/app/reducers/authenticationReducer.js @@ -37,7 +37,6 @@ export default createReducer(initialState, { groups: payload.tokenData.metadata.groups.split(/,/), policies: payload.tokenData.policies, authTokenTimeoutId: payload.authTokenTimeoutId, - sessionWarningTimeoutId: payload.sessionWarningTimeoutId }) }, // logs the user out and resets user data diff --git a/package.json b/package.json index e1cf66b..2e189a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cerberus-management-dashboard", - "version": "1.2.0", + "version": "1.2.1", "description": "A management dashboard for Cerberus.", "main": "index.js", "repository": {