Skip to content

Build your personal knowledge base with Trilium Notes

moved protected session expiration scheduling #2855

zadam37eb16b2f30f
diff --git a/src/services/protected_session.js b/src/services/protected_session.js
index 22e5317385..c6098cc2fd 100644
--- a/src/services/protected_session.js
+++ b/src/services/protected_session.js
@@ -3,7 +3,6 @@
const log = require('./log');
const dataEncryptionService = require('./data_encryption');
const options = require("./options");
-const sqlInit = require("./sql_init");
let dataKey = null;
@@ -64,20 +63,19 @@ function touchProtectedSession() {
}
}
-sqlInit.dbReady.then(() => {
- setInterval(() => {
- const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout');
- if (isProtectedSessionAvailable()
- && lastProtectedSessionOperationDate
- && Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
+function checkProtectedSessionExpiration() {
+ const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout');
+ if (isProtectedSessionAvailable()
+ && lastProtectedSessionOperationDate
+ && Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
- resetDataKey();
+ resetDataKey();
- require('./ws').reloadFrontend();
- }
- }, 30000);
-});
+ log.info("Expiring protected session");
+ require('./ws').reloadFrontend();
+ }
+}
module.exports = {
setDataKey,
@@ -87,5 +85,6 @@ module.exports = {
decrypt,
decryptString,
decryptNotes,
- touchProtectedSession
+ touchProtectedSession,
+ checkProtectedSessionExpiration
};
diff --git a/src/services/scheduler.js b/src/services/scheduler.js
index f2d88e09a7..3f253ba9b3 100644
--- a/src/services/scheduler.js
+++ b/src/services/scheduler.js
@@ -6,6 +6,7 @@ const log = require('./log');
const sql = require("./sql");
const becca = require("../becca/becca");
const specialNotesService = require("../services/special_notes");
+const protectedSessionService = require("../services/protected_session");
function getRunAtHours(note) {
try {
@@ -59,4 +60,6 @@ sqlInit.dbReady.then(() => {
setTimeout(cls.wrap(() => specialNotesService.createMissingSpecialNotes()), 10 * 1000);
}
+
+ setInterval(() => protectedSessionService.checkProtectedSessionExpiration(), 30000);
});