From 048936d576c5dcafc605c143cd0dd61959e89807 Mon Sep 17 00:00:00 2001 From: cgjgh <160297365+cgjgh@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:55:52 -0500 Subject: [PATCH] Add and expose detected users array to Node-RED context --- nodes/config/ui_base.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nodes/config/ui_base.js b/nodes/config/ui_base.js index 36246b3d0..f8ac39d49 100644 --- a/nodes/config/ui_base.js +++ b/nodes/config/ui_base.js @@ -379,6 +379,23 @@ module.exports = function (RED) { // Assign allowed pages or null if not found allowedPages = user?.allowedPages ?? null + + // Add userId and last detected to global.store.detectedUsers + if (userId) { + // eslint-disable-next-line prefer-const + const currentTime = Math.floor(Date.now() / 1000) + + // get detectedUsers from store + let detectedUsers = store?.detectedUsers || {} + + if (!detectedUsers) { + detectedUsers = {} + } + detectedUsers[userId] = { userId, lastDetected: currentTime } + + // update the global store + node.context().global.set('store.detectedUsers', detectedUsers) + } } // Initialize userPages based on filter disabled or zeroTrust value - start with empty map for zero trust