@ -107,9 +107,18 @@ module.exports = function (User) {
return ;
}
await cleanExpiredSessions ( uid ) ;
await revokeSessionsAboveThreshold ( uid , meta . config . maxUserSessions ) ;
await db . sortedSetAdd ( 'uid:' + uid + ':sessions' , Date . now ( ) , sessionId ) ;
} ;
async function revokeSessionsAboveThreshold ( uid , maxUserSessions ) {
const activeSessions = await db . getSortedSetRange ( 'uid:' + uid + ':sessions' , 0 , - 1 ) ;
if ( activeSessions . length > maxUserSessions ) {
const sessionsToRevoke = activeSessions . slice ( 0 , activeSessions . length - maxUserSessions ) ;
await Promise . all ( sessionsToRevoke . map ( sessionId => User . auth . revokeSession ( sessionId , uid ) ) ) ;
}
}
User . auth . revokeSession = async function ( sessionId , uid ) {
winston . verbose ( '[user.auth] Revoking session ' + sessionId + ' for user ' + uid ) ;
const sessionObj = await getSessionFromStore ( sessionId ) ;