summaryrefslogtreecommitdiff
path: root/middlewares/sessions.js
blob: 8697ae0cff4c79d2966d7d535685bf306b6161b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import expressSession from "express-session";
import sqlite from "better-sqlite3";
import sqliteStore from "better-sqlite3-session-store";

const SqliteStore = sqliteStore(expressSession);
const db = new sqlite("sessions.db", process.env.NODE_ENV === "production" ? null : { verbose: console.log });
const secret = process.env.SESSION_SECRET || "secret";
const session = expressSession({
	cookie: {
		httpOnly: true,
		maxAge: 1000 * 60 * 60 * 24 * 15, // 15 days
		sameSite: "Strict",
		secure: process.env.NODE_ENV === "production" ? true : false,
	},
	name: "JDMSessionId",
	saveUninitialized: false,
	secret: secret,
	store: new SqliteStore({
		client: db,
		expired: {
			clear: true,
			intervalMs: 1000 * 60 * 60, // 60min
		}
	}),
	resave: false,
	unset: "destroy",
});

export default session;