Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mfancher/no revoke active session fix #983

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const MyAccountTable = ({ user }) => {
if (!sessions?.success) {
return;
}

setSessions(sessions.data);
return;
};
Expand All @@ -36,7 +37,10 @@ const MyAccountTable = ({ user }) => {
title: 'Revoke',
dataIndex: 'id',
key: 'id',
render: (id) => {
render: (id, current) => {
if (current.current) {
return <span>Active Session</span>;
}
return (
<a
onClick={async () => {
Expand Down
11 changes: 11 additions & 0 deletions Tombolo/server/controllers/sessionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
Loading