From 263a77cd074f7a8008bc60c6e4bf80d4a0c68221 Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Thu, 11 Jul 2024 19:29:56 +0200 Subject: [PATCH] feat: add eventListener in Atlas for Gen3 logout event --- .../ohdsi-atlas/ohdsi-atlas-config-local.yaml | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/kube/services/ohdsi-atlas/ohdsi-atlas-config-local.yaml b/kube/services/ohdsi-atlas/ohdsi-atlas-config-local.yaml index 7c686df913..a65b89f739 100644 --- a/kube/services/ohdsi-atlas/ohdsi-atlas-config-local.yaml +++ b/kube/services/ohdsi-atlas/ohdsi-atlas-config-local.yaml @@ -4,7 +4,7 @@ metadata: name: ohdsi-atlas-config-local data: config-local.js: | - define([], function () { + define(['components/welcome'], function (welcome) { var configLocal = {}; // WebAPI configLocal.api = { @@ -33,6 +33,12 @@ data: return configLocal; }); + ///////////////////////////////////////////////////////////// + // Code to post messages to Gen3 to keep the Gen3 session + // alive when the user is busy in Atlas (which is in an iframe + // inside Gen3 portal). + ///////////////////////////////////////////////////////////// + var parentOfThisIframe = window.parent; var mouseoverCount = 0; @@ -45,3 +51,28 @@ data: mouseoverCount = 0; } }); + + ///////////////////////////////////////////////////////////// + // Code to process logout message from Gen3 portal to + // ensure the user is logged out of Atlas when clicking logout + // in Gen3 portal. + ///////////////////////////////////////////////////////////// + + window.addEventListener('message', this.processParentIncomingMessages); + processParentIncomingMessages = (event) => { + const host = $hostname; + const applicationBaseUrl = `https//${host}`; + + // ONLY process messages coming from the same domain as the app AND + // which contain the message "logout user!": + if ( + event.origin === applicationBaseUrl + && event.data === 'logout user!' + ) { + // Call function to logout user from Atlas: + welcome.signout(); + } + }; + // post message back acknowledging receipt and successful Atlas + // logout: + // TODO