mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
The snap, Docker, docker-compose and start scripts have offered LOGOUT_WITH_TIMER, LOGOUT_IN, LOGOUT_ON_HOURS and LOGOUT_ON_MINUTES since 2018, but the code that read them was removed with the job queue it ran on, so they did nothing. Per the maintainer decision of 2026-10-08 they work again. A login ends LOGOUT_IN days after it was made, or at LOGOUT_ON_HOURS:LOGOUT_ON_MINUTES server time (the next such time, or on the day LOGOUT_IN days later). Once a minute the server removes the expired login tokens in one query, and Meteor signs out the browsers that used them. The four settings are overridable in Admin Panel / People / Login like the other login variables, with hours and minutes bounded. An unusable combination signs nobody out and the server log says why. tests/logoutTimer.test.cjs checks the one-query cutoff against the per-login deadline over two years of logins in three time zones, two of them with daylight saving time. Thanks to xet7 !
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { authEnv, onAuthConfigChange } from '/server/lib/authConfig';
|
|
|
|
// Automatic logout (LOGOUT_WITH_TIMER, LOGOUT_IN, LOGOUT_ON_HOURS,
|
|
// LOGOUT_ON_MINUTES; Admin Panel / People / Login overrides each). Once a
|
|
// minute, every login token whose deadline has passed is removed; Meteor then
|
|
// logs out the connections that used it. The deadline arithmetic is
|
|
// models/lib/logoutTimer.js.
|
|
const { logoutTimerConfig, expiredBefore } = require('/models/lib/logoutTimer');
|
|
|
|
const SWEEP_MS = 60 * 1000;
|
|
let lastReason = null;
|
|
|
|
export async function sweepExpiredLogins(now = new Date()) {
|
|
const config = logoutTimerConfig(authEnv);
|
|
if (!config.enabled) {
|
|
// Say once why a timer that was asked for does nothing.
|
|
if (config.reason !== 'off' && config.reason !== lastReason) {
|
|
console.warn(`[logout-timer] not running: ${config.reason}`);
|
|
}
|
|
lastReason = config.reason;
|
|
return 0;
|
|
}
|
|
lastReason = null;
|
|
const cutoff = expiredBefore(now, config);
|
|
return Meteor.users.updateAsync(
|
|
{ 'services.resume.loginTokens.when': { $lt: cutoff } },
|
|
{ $pull: { 'services.resume.loginTokens': { when: { $lt: cutoff } } } },
|
|
{ multi: true },
|
|
);
|
|
}
|
|
|
|
async function sweep() {
|
|
try {
|
|
const users = await sweepExpiredLogins();
|
|
if (users) console.log(`[logout-timer] signed out expired logins of ${users} user(s)`);
|
|
} catch (error) {
|
|
console.error('[logout-timer] sweep failed:', error);
|
|
}
|
|
}
|
|
|
|
Meteor.startup(() => {
|
|
Meteor.setInterval(sweep, SWEEP_MS);
|
|
Meteor.defer(sweep);
|
|
});
|
|
|
|
// A change in Admin Panel / People / Login applies at once, not a minute later.
|
|
onAuthConfigChange('login', () => { Meteor.defer(sweep); });
|