Skip to content

Commit b42fa4b

Browse files
Merge pull request #82 from QuCodeXClub/fix/frontend-bugs-and-ui-improvements
feat: add admin authentication flow with OTP verification and session…
2 parents 2c716f1 + 343b58f commit b42fa4b

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎Backend/src/controllers/admin.controller.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,19 @@ const logoutAdmin = asyncHandler(async (req, res) => {
210210
.json(new ApiResponse(200, {}, 'Admin logged out successfully'));
211211
});
212212

213-
// @desc Get all sessions for current admin with status tags
213+
// @desc Get all sessions for all admins with status tags
214214
// @route GET /api/v1/admin/sessions
215215
// @access Private/Admin
216216
const getAdminSessions = asyncHandler(async (req, res) => {
217217
// Update expired active sessions
218218
await Session.updateMany(
219-
{ adminId: req.admin._id, status: 'ACTIVE', expiresAt: { $lt: new Date() } },
219+
{ status: 'ACTIVE', expiresAt: { $lt: new Date() } },
220220
{ status: 'EXPIRED' }
221221
);
222222

223-
const rawSessions = await Session.find({ adminId: req.admin._id }).sort({ createdAt: -1 });
223+
const rawSessions = await Session.find()
224+
.populate('adminId', 'name email profilePhoto')
225+
.sort({ createdAt: -1 });
224226

225227
const sessions = rawSessions.map((session) => {
226228
const obj = session.toObject();
@@ -231,7 +233,7 @@ const getAdminSessions = asyncHandler(async (req, res) => {
231233
return res.status(200).json(new ApiResponse(200, sessions, 'Sessions fetched successfully'));
232234
});
233235

234-
// @desc Kill or delete a specific session
236+
// @desc Kill or delete a specific session across any admin account
235237
// @route DELETE /api/v1/admin/sessions/:id
236238
// @access Private/Admin
237239
const killSession = asyncHandler(async (req, res) => {
@@ -241,7 +243,7 @@ const killSession = asyncHandler(async (req, res) => {
241243
throw new ApiError(400, 'Cannot revoke your current active session. Use Logout instead.');
242244
}
243245

244-
const session = await Session.findOne({ _id: id, adminId: req.admin._id });
246+
const session = await Session.findById(id);
245247

246248
if (!session) {
247249
throw new ApiError(404, 'Session not found');
@@ -251,6 +253,8 @@ const killSession = asyncHandler(async (req, res) => {
251253
session.loggedOutAt = new Date();
252254
await session.save();
253255

256+
await session.populate('adminId', 'name email profilePhoto');
257+
254258
return res.status(200).json(new ApiResponse(200, session, 'Session revoked successfully'));
255259
});
256260

‎Frontend/src/pages/admin/ManageSessions.jsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
LogOut,
1818
ShieldAlert,
1919
Clock,
20+
User,
2021
} from "lucide-react";
2122
import { SessionCardSkeleton } from "../../components/common/skeletons";
2223

@@ -185,6 +186,14 @@ export default function ManageSessions() {
185186
{renderStatusBadge(session)}
186187
</div>
187188

189+
{session.adminId && (
190+
<div className="text-xs font-mono font-medium text-text-muted flex items-center gap-1.5 mt-1 mb-1 bg-card-hover/50 px-2 py-0.5 rounded-md border border-border/40 w-fit">
191+
<User className="w-3.5 h-3.5 text-accent shrink-0" />
192+
<span className="font-semibold text-text">{session.adminId.name || "Admin"}</span>
193+
<span>({session.adminId.email || "N/A"})</span>
194+
</div>
195+
)}
196+
188197
<div className="mt-1.5 space-y-1">
189198
<p className="text-xs font-mono text-text-muted flex items-center gap-2">
190199
<Globe className="w-3.5 h-3.5 text-accent" />

0 commit comments

Comments
 (0)