sessions hav expiry dates
This commit is contained in:
parent
b4bd150d93
commit
e528f1351a
3 changed files with 28 additions and 1 deletions
5
src/constants.js
Normal file
5
src/constants.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const DEFAULT_SESSION_DURATION_SECONDS = 60 * 60 * 24 * 30;
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_SESSION_DURATION_SECONDS
|
||||
}
|
||||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue