check if session is expired

This commit is contained in:
counterweight 2025-02-10 12:43:46 +01:00
parent e528f1351a
commit 7c2514a9a6
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 51 additions and 19 deletions

View file

@ -6,7 +6,6 @@ const SessionNpubbed = require('../models/SessionNpubbed');
const constants = require('../constants');
async function createSession(sessionUuid) {
const currentTimestamp = new Date();
const expiryTimestamp = new Date(currentTimestamp.getTime());
expiryTimestamp.setSeconds(expiryTimestamp.getSeconds() + constants.DEFAULT_SESSION_DURATION_SECONDS);
@ -18,6 +17,24 @@ async function createSession(sessionUuid) {
});
}
async function isSessionExpired(sessionUuid) {
const currentSession = await Session.findOne({
where: {
'uuid': sessionUuid
}
});
if (!currentSession) {
return true;
}
if (currentSession.expires_at <= new Date()) {
return true;
}
return false;
}
async function relateSessionToNpub(sessionUuid, npub) {
await SessionNpubbed.create({
session_npubbed_uuid: uuid.v7(),
@ -34,16 +51,18 @@ async function isSessionAlreadyRelatedToNpub(sessionUuid, npub) {
return false;
}
/* async function getNpubRelatedToSession(sessionUuid) {
if (SessionNpubbed.findOne({
where: { 'sessionUuid': sessionUuid }
}))
}
async function isSessionAuthorized(sessionUuid) {
} */
exports.createSession = createSession;
exports.isSessionExpired = isSessionExpired;
exports.relateSessionToNpub = relateSessionToNpub;
exports.isSessionAlreadyRelatedToNpub = isSessionAlreadyRelatedToNpub;