From e9d52a6be43abd1691229a971f53117ab1b5d650 Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Thu, 2 Jun 2022 22:09:22 +0200 Subject: [PATCH 1/4] adding a event listener to capture messages posted by the app This generic solution allows for any future app to use postMessage to keep user session alive --- src/Analysis/AnalysisApp.jsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Analysis/AnalysisApp.jsx b/src/Analysis/AnalysisApp.jsx index 1d17c6e60a..e0c8c01ee6 100644 --- a/src/Analysis/AnalysisApp.jsx +++ b/src/Analysis/AnalysisApp.jsx @@ -9,6 +9,9 @@ import HIVCohortFilter from '../HIVCohortFilter/HIVCohortFilter'; import ReduxGWASUIApp from './GWASUIApp/ReduxGWASUIApp'; import { analysisApps } from '../localconf'; import './AnalysisApp.css'; +import sessionMonitor from '../SessionMonitor'; +// monitor user's session +sessionMonitor.start(); const queryClient = new QueryClient(); @@ -52,6 +55,22 @@ class AnalysisApp extends React.Component { queryClient.invalidateQueries('workflows'); } + processAppMessages = (event) => { + const pathArray = this.state.app.applicationUrl.split( '/' ); + const protocol = pathArray[0]; + const host = pathArray[2]; + const applicationBaseUrl = protocol + '//' + host; + + // ONLY process messages coming from the app AND + // which contain the message "refresh token!": + if (event.origin === applicationBaseUrl && + event.data === "refresh token!") { + console.log( "received: " + event.data ); + //Call function to refresh session: + sessionMonitor.updateUserActivity(); + } + } + getAppContent = (app) => { switch (app) { case 'vaGWAS': @@ -84,6 +103,8 @@ class AnalysisApp extends React.Component { ); default: + // this will ensure the main window will process the app messages (if any): + window.addEventListener("message", this.processAppMessages); return (
From 5f72eca09d88d9f842aa3033b7ce618a6cf842c1 Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Thu, 2 Jun 2022 22:33:00 +0200 Subject: [PATCH 2/4] improve comment regarding processAppMessages check --- src/Analysis/AnalysisApp.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analysis/AnalysisApp.jsx b/src/Analysis/AnalysisApp.jsx index e0c8c01ee6..f13b15dd63 100644 --- a/src/Analysis/AnalysisApp.jsx +++ b/src/Analysis/AnalysisApp.jsx @@ -61,7 +61,7 @@ class AnalysisApp extends React.Component { const host = pathArray[2]; const applicationBaseUrl = protocol + '//' + host; - // ONLY process messages coming from the app AND + // ONLY process messages coming from the same domain as the app AND // which contain the message "refresh token!": if (event.origin === applicationBaseUrl && event.data === "refresh token!") { From 5b58ba55b5fd125bf5deed72e8faf5ee7f77a1ee Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Tue, 7 Jun 2022 20:14:27 +0200 Subject: [PATCH 3/4] removed unnecessary code for starting sessionmonitor --- src/Analysis/AnalysisApp.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analysis/AnalysisApp.jsx b/src/Analysis/AnalysisApp.jsx index f13b15dd63..7fcba3f561 100644 --- a/src/Analysis/AnalysisApp.jsx +++ b/src/Analysis/AnalysisApp.jsx @@ -10,8 +10,6 @@ import ReduxGWASUIApp from './GWASUIApp/ReduxGWASUIApp'; import { analysisApps } from '../localconf'; import './AnalysisApp.css'; import sessionMonitor from '../SessionMonitor'; -// monitor user's session -sessionMonitor.start(); const queryClient = new QueryClient(); From 9a600cb77e4ab90b89d5544a04d85332a754b091 Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Tue, 7 Jun 2022 20:17:23 +0200 Subject: [PATCH 4/4] remove console.log entry --- src/Analysis/AnalysisApp.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Analysis/AnalysisApp.jsx b/src/Analysis/AnalysisApp.jsx index 7fcba3f561..c3d36cb1ae 100644 --- a/src/Analysis/AnalysisApp.jsx +++ b/src/Analysis/AnalysisApp.jsx @@ -63,7 +63,6 @@ class AnalysisApp extends React.Component { // which contain the message "refresh token!": if (event.origin === applicationBaseUrl && event.data === "refresh token!") { - console.log( "received: " + event.data ); //Call function to refresh session: sessionMonitor.updateUserActivity(); }