Added refresh tokens
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user