Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #19 from Nike-Inc/bugfix/remove_timeout_methods_we…
Browse files Browse the repository at this point in the history
…re_not_dispatched

Bugfix: Make sure 'remove timeout' methods are dispatched
  • Loading branch information
sdford authored May 24, 2017
2 parents 803496d + 324c2ac commit 31ed1b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions app/actions/authenticationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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')
})
Expand All @@ -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())
Expand Down
1 change: 0 additions & 1 deletion app/reducers/authenticationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 31ed1b7

Please sign in to comment.