@@ -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
216216const 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
237239const 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
0 commit comments