Added refresh tokens

This commit is contained in:
Johnathon Slightham
2021-06-11 12:03:50 -04:00
parent fdb447a9ee
commit 531a4d632b
6 changed files with 51 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
const config = require('../config');
let Session = require('../schema/session.model');
const maxSessionLength = config.maxSessionLength;
const maxRefreshLength = config.maxRefreshLength;
// purgeSessions() purge sessions that have existed for longer than maxSessionLength
const purgeSessions = () => {
@@ -9,7 +10,12 @@ const purgeSessions = () => {
for (let i = 0; i < arr.length; i++) {
let timeDifference = new Date().getTime() - arr[i].date;
let dayDifference = timeDifference / (1000 * 3600 * 24);
if (dayDifference > maxSessionLength) {
if (arr[i].type == 0 && dayDifference > maxSessionLength) {
arr[i].delete().catch(e => {
console.log(e);
});
}
if (arr[i].type == 1 && dayDifference > maxRefreshLength) {
arr[i].delete().catch(e => {
console.log(e);
});