summaryrefslogtreecommitdiff
path: root/middlewares/sessions.js
diff options
context:
space:
mode:
authorJulien Dessaux2022-10-27 23:56:29 +0200
committerJulien Dessaux2022-10-27 23:56:29 +0200
commit2611ded920a8345922346ed0d43e4efdd94401a1 (patch)
tree3313d976fbb11bdbfd1841ce336cc4372f9ab32c /middlewares/sessions.js
parentAllow for placing the first word (diff)
downloadjeux-de-mots-2611ded920a8345922346ed0d43e4efdd94401a1.tar.gz
jeux-de-mots-2611ded920a8345922346ed0d43e4efdd94401a1.tar.bz2
jeux-de-mots-2611ded920a8345922346ed0d43e4efdd94401a1.zip
Began implementing middlewares, session and auth
Diffstat (limited to 'middlewares/sessions.js')
-rw-r--r--middlewares/sessions.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/middlewares/sessions.js b/middlewares/sessions.js
new file mode 100644
index 0000000..6112a8c
--- /dev/null
+++ b/middlewares/sessions.js
@@ -0,0 +1,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", { 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;