sessions hav expiry dates

This commit is contained in:
counterweight 2025-02-10 12:17:15 +01:00
parent b4bd150d93
commit e528f1351a
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 28 additions and 1 deletions

5
src/constants.js Normal file
View file

@ -0,0 +1,5 @@
const DEFAULT_SESSION_DURATION_SECONDS = 60 * 60 * 24 * 30;
module.exports = {
DEFAULT_SESSION_DURATION_SECONDS
}

View file

@ -11,6 +11,10 @@ const Session = sequelize.define('Session', {
created_at: {
type: DataTypes.DATE,
allowNull: false
},
expires_at: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'session'

View file

@ -3,10 +3,18 @@ const uuid = require("uuid");
const Session = require('../models/Session');
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);
await Session.create({
uuid: sessionUuid,
created_at: new Date().toISOString()
created_at: currentTimestamp.toISOString(),
expires_at: expiryTimestamp.toISOString()
});
}
@ -26,6 +34,16 @@ 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.relateSessionToNpub = relateSessionToNpub;
exports.isSessionAlreadyRelatedToNpub = isSessionAlreadyRelatedToNpub;