diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index dcb57ed7f0e694b9d7276b17f697993328cb3c7d..44fbe6737fc7a6a7de46f5420115867a2286b983 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -27,9 +27,6 @@ const ViamAPI = require('../../temp/viamapi');
 
 var identityColors = ["#994392", "#cb0767", "#e51d31", "#ec671b", "#fab610"];
 
-/** This flag blocks execution of getNewEvents while we logging out **/
-let logoutInProgress = false;
-
 function getNextColor() {
   var colorIndex = localStorage.getItem("colorIndex");
   if (colorIndex == null || colorIndex === "") {
@@ -723,17 +720,20 @@ const connection = Penpal.connectToParent({
           };
         }
 
-        logoutInProgress = true;
+        // Clone headers to be able destroy authentication first
+        const headers = {...window.viamApi.getConfig().headers};
+
+        destroyAuthentication();
 
         const identityLogoutResponse = await executeRestfulFunction(
           "private",
           window.viamApi,
           window.viamApi.identityLogout,
-          null
+          {
+            headers
+          }
         );
 
-        destroyAuthentication();
-
         return identityLogoutResponse;
       } catch (e) {
         return {
@@ -741,8 +741,6 @@ const connection = Penpal.connectToParent({
           code: "400",
           status: e.message
         };
-      } finally {
-        logoutInProgress = false;
       }
     },
     identityRestoreAccess(restoreAccessIdentity, identificator) {
@@ -1425,10 +1423,6 @@ connection.promise.then(parent => {
   }
 
   setInterval(() => {
-    if (logoutInProgress) {
-      return;
-    }
-
     if (window.currentlyLoadedIdentity && !anynomousDeviceKeyEventsProcessing && !window.currentlyAuthenticatedIdentity) {
       getNewEventsWithoutSession();
     }