1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 21:29:43 +02:00
planka/server/api/hooks/watcher/index.js
Maksim Eltyshev 2ee1166747 feat: Version 2
Closes #627, closes #1047
2025-05-10 02:09:06 +02:00

43 lines
1.1 KiB
JavaScript

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* watcher hook
*
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions,
* and/or initialization logic.
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
*/
module.exports = function defineWatcherHook(sails) {
const checkSocketConnectionsToLogout = () => {
[...sails.io.sockets.adapter.rooms.keys()].forEach((room) => {
if (!room.startsWith('@accessToken:')) {
return;
}
const accessToken = room.split(':')[1];
try {
sails.helpers.utils.verifyJwtToken(accessToken);
} catch (error) {
sails.sockets.broadcast(room, 'logout');
sails.sockets.leaveAll(room);
}
});
};
return {
/**
* Runs when this Sails app loads/lifts.
*/
async initialize() {
sails.log.info('Initializing custom hook (`watcher`)');
setInterval(checkSocketConnectionsToLogout, 60 * 1000);
},
};
};