I'm using apex 20.1 and universal theme.
I have a global page that has dialog closed even that executes a JS.
My issue is if the current page app timed out, apex display a dialog page if you want to re-login or cancel

From here if I click "CANCEL" it goes back to the page and when I click to do anything apex displays the page below

The issue is when user clicks "OK" the common JS DA on the global page is firing but since the session is invalid APEX displays this page again.
this basically results to infinite loop and the only way out is for you to close the browser.
The idea is if there is a way to check if the current APEX session is valid then I can add this to my global common DA to check it first.
Thanks