check if session is expired
This commit is contained in:
parent
e528f1351a
commit
7c2514a9a6
4 changed files with 51 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue