Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tokenExpiresDate.setTime(cerberusAuthTokenExpiresDateInMilliseconds)
log.debug(`Setting session timeout to ${tokenExpiresDate}`)
let timeToExpireTokenInMillis = tokenExpiresDate.getTime() - now.getTime()
let sessionExpirationCheckIntervalInMillis = 2000
let sessionExpirationCheckIntervalId = workerTimers.setInterval(() => {
let currentTimeInMillis = new Date().getTime()
let sessionExpirationTimeInMillis = tokenExpiresDate.getTime()
if (currentTimeInMillis >= sessionExpirationTimeInMillis) {
dispatch(handleSessionExpiration())
}
}, sessionExpirationCheckIntervalInMillis)
let sessionWarningTimeoutId = workerTimers.setTimeout(() => {
dispatch(warnSessionExpiresSoon(token))
}, timeToExpireTokenInMillis - 120000) // warn two minutes before expiration
dispatch(setSessionWarningTimeoutId(sessionWarningTimeoutId))
sessionStorage.setItem('token', JSON.stringify(response.data))
sessionStorage.setItem('tokenExpiresDate', tokenExpiresDate)
sessionStorage.setItem('userRespondedToSessionWarning', false)
dispatch(messengerActions.clearAllMessages())
dispatch(loginUserSuccess(response.data, sessionExpirationCheckIntervalId))
dispatch(appActions.fetchSideBarData(token))
if (redirectToWelcome) {
hashHistory.push("/")
}
}
return function(dispatch) {
let userHasRespondedToSessionWarning = sessionStorage.getItem('userRespondedToSessionWarning') === "true";
if (! userHasRespondedToSessionWarning) {
let sessionWarningTimeoutId = workerTimers.setTimeout(() => {
dispatch(warnSessionExpiresSoon(tokenStr))
}, timeToWarnInMillis)
dispatch(setSessionWarningTimeoutId(sessionWarningTimeoutId))
}
}
}
.then(function (response) {
dispatch(handleRemoveSessionExpirationCheck())
dispatch(removeSessionWarningTimeout())
workerTimers.setTimeout(function(){
handleUserLogin(response, dispatch, false)
if (redirect) {
hashHistory.push(redirectPath)
}
}, 2000);
})
.catch(function (response) {