Skip to content

Commit

Permalink
Merge pull request #2329 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Use session storage in case of user inactivity
  • Loading branch information
simonredfern authored Nov 17, 2023
2 parents 5da518c + 9bea84e commit 27594d3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions obp-api/src/main/webapp/media/js/inactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,22 @@ function logout() {
}

async function makeObpApiCall() {
let response = await fetch('/obp/v5.1.0/ui/suggested-session-timeout');
let json = await response.json();
console.log(json.timeout_in_seconds);
localStorage.setItem("suggested-session-timeout-in-seconds", json.timeout_in_seconds);
const response = await fetch('/obp/v5.1.0/ui/suggested-session-timeout');
const json = await response.json();
return json.timeout_in_seconds;
}

function getSuggestedSessionTimeout() {
if(!localStorage.getItem("suggested-session-timeout-in-seconds")) {
makeObpApiCall();
async function getSuggestedSessionTimeout() {
if(!sessionStorage.getItem("suggested-session-timeout-in-seconds")) {
let timeoutInSeconds = await makeObpApiCall();
sessionStorage.setItem("suggested-session-timeout-in-seconds", timeoutInSeconds);
}
return localStorage.getItem("suggested-session-timeout-in-seconds") * 1000 + 1000; // We need timeout in millis
return sessionStorage.getItem("suggested-session-timeout-in-seconds") * 1000 + 1000; // We need timeout in millis
}

// self executing function to trigger the operation on page load
(function () {
timeoutIntervalInMillis = getSuggestedSessionTimeout();
console.log(timeoutIntervalInMillis);
(async function () {
timeoutIntervalInMillis = await getSuggestedSessionTimeout();
const elem = document.getElementById("loggedIn-username");
if(elem) {
// to prevent any lingering timeout handlers preventing memory leaks
Expand Down

0 comments on commit 27594d3

Please sign in to comment.