From fbef9bc928d187d3a29ac97c2eab8934cb004719 Mon Sep 17 00:00:00 2001 From: FancMa01 Date: Fri, 3 Jan 2025 08:44:38 -0700 Subject: [PATCH] Mfancher/no revoke active session fix (#983) * Wire Password Reset * Remove unecessary reset temp password code that isn't used with temp password. We use the link and token method for resetting temp passwords, no need to have temporary password code any longer * Flag session from the requested token with current --- .../application/myAccount/myAccountTable.jsx | 6 +++++- Tombolo/server/controllers/sessionController.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Tombolo/client-reactjs/src/components/application/myAccount/myAccountTable.jsx b/Tombolo/client-reactjs/src/components/application/myAccount/myAccountTable.jsx index 29256172..5ecdb086 100644 --- a/Tombolo/client-reactjs/src/components/application/myAccount/myAccountTable.jsx +++ b/Tombolo/client-reactjs/src/components/application/myAccount/myAccountTable.jsx @@ -12,6 +12,7 @@ const MyAccountTable = ({ user }) => { if (!sessions?.success) { return; } + setSessions(sessions.data); return; }; @@ -36,7 +37,10 @@ const MyAccountTable = ({ user }) => { title: 'Revoke', dataIndex: 'id', key: 'id', - render: (id) => { + render: (id, current) => { + if (current.current) { + return Active Session; + } return ( { diff --git a/Tombolo/server/controllers/sessionController.js b/Tombolo/server/controllers/sessionController.js index 5d8de27a..0a6b9ed6 100644 --- a/Tombolo/server/controllers/sessionController.js +++ b/Tombolo/server/controllers/sessionController.js @@ -2,6 +2,7 @@ const jwt = require("jsonwebtoken"); const models = require("../models"); const { blacklistToken } = require("../utils/tokenBlackListing"); const logger = require("../config/logger"); +const { verifyToken } = require("../utils/authUtil"); const RefreshTokens = models.RefreshTokens; @@ -26,6 +27,16 @@ const activeSessionsByUserId = async (req, res) => { } }); + //grab current session token id from the request + const token = req.cookies.token; + let decoded = await verifyToken(token, process.env.JWT_SECRET); + const currentTokenId = decoded.tokenId; + + // Mark the current token + activeSessions.forEach((session) => { + session.dataValues.current = session.id === currentTokenId; + }); + // response res.status(200).json({ success: true, data: activeSessions }); } catch (err) {